Shared memory operations atomic?

Shared memory operations atomic?

Post by Eivind Trondse » Tue, 02 Mar 1999 04:00:00



Hi all

Is writing to a shared memory segment an atomic operation? I am writing
an application needing to cache data from a database on an apache
webserver. I thought I'd use the shm* range of system calls, but if I
have to use semaphores too I think I have too few of them for all the
distinct data units I need to store.

It is actually a Perl-module, but it doesn't seem to be possible to
address multiple blocks in the perl mapping of the shm* calls.

This system will run on Linux2.2.

Any advice greatly appreciated.

--
Eivind Trondsen - SOL B?rs AS               http://www.solbors.no
Tlf  22 80 79 85                  
Fax 22 80 79 79                        Quidquid latine dictum sit,
Mob 924 14 969                                      altum viditur.

 
 
 

Shared memory operations atomic?

Post by Jack Kle » Tue, 02 Mar 1999 04:00:00


On Mon, 01 Mar 1999 15:52:51 +0100, Eivind Trondsen


> Hi all

> Is writing to a shared memory segment an atomic operation? I am writing
> an application needing to cache data from a database on an apache
> webserver. I thought I'd use the shm* range of system calls, but if I
> have to use semaphores too I think I have too few of them for all the
> distinct data units I need to store.

> It is actually a Perl-module, but it doesn't seem to be possible to
> address multiple blocks in the perl mapping of the shm* calls.

> This system will run on Linux2.2.

> Any advice greatly appreciated.

<Jack>

Please leave comp.lang.c off your cross post list for platform
specific questions.  There is no shared memory in ANSI/ISO C.

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.

 
 
 

Shared memory operations atomic?

Post by Bas de Bakke » Tue, 02 Mar 1999 04:00:00


    Eivind> Is writing to a shared memory segment an atomic operation?

That depends on your hardware (and the size of the data that you're
writing), but even if it is on your hardware, I would strongly advise
against depending on it.  It will make your program non-portable,
perhaps even to the next revision of your CPU.

    Eivind> I thought I'd use the shm* range of system calls, but if I
    Eivind> have to use semaphores too I think I have too few of them
    Eivind> for all the distinct data units I need to store.

You'll have to use semaphores or similar constructs (like
process-shared pthread mutexes (currently unavailable in Linux)).
Perhaps you can protect larger amounts of data (particularly those
often written together) with a single semaphore.

Regards,
Bas.

 
 
 

Shared memory operations atomic?

Post by wetbo » Tue, 02 Mar 1999 04:00:00



: Hi all

: Is writing to a shared memory segment an atomic operation?

Not unless you use processor-specific bus interlock instructions.
Check your compiler -- there may be system specific language
extensions that allow you to access these instructions, or
you may have to step into assembly language.

-- Wetboy

 
 
 

1. remove mixture of non-atomic operations with page->flags which requires atomic operations to access

page->flags is effectively a lock word as its various bits are updatable
and accessible only by atomic operations. This patch removes the update
of page->flags in __free_pages_ok() with non-atomic operations in favor
of using atomic bit operations to update the bits to be cleared.

Against 2.5.19.

Cheers,
Bill

diff -Nru a/include/linux/page-flags.h b/include/linux/page-flags.h
--- a/include/linux/page-flags.h        Sun Jun  2 15:42:49 2002

 #define PageChecked(page)      test_bit(PG_checked, &(page)->flags)
 #define SetPageChecked(page)   set_bit(PG_checked, &(page)->flags)
+#define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)

 #define PageReserved(page)     test_bit(PG_reserved, &(page)->flags)
 #define SetPageReserved(page)  set_bit(PG_reserved, &(page)->flags)
diff -Nru a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c   Sun Jun  2 15:42:49 2002

        BUG_ON(PageLRU(page));
        BUG_ON(PageActive(page));
        BUG_ON(PageWriteback(page));
+
        ClearPageDirty(page);
-       page->flags &= ~(1<<PG_referenced);
+       ClearPageUptodate(page);
+       ClearPageSlab(page);
+       ClearPageNosave(page);
+       ClearPageChecked(page);

        if (current->flags & PF_FREE_PAGES)
                goto local_freelist;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. PCMCIA Modem Problem

3. atomic operations in solaris (atomic.h)

4. tftp

5. Atomic Shared Memory Writes

6. Linux Market Share?

7. Shared memory operation on Solaris,help

8. Simple DHCP Question

9. Is it an atomic operation !!!???

10. Solaris atomic/interlocked increment/swap operations?

11. Atomic/transaction operations on UFS

12. Atomic operations at Solaris

13. Atomic operations