2009-03-27 09:35:03

by Metzger, Markus T

[permalink] [raw]
Subject: [patch 2/14] x86, mm: add release_locked_buffer_on_behalf

Allow the release of a locked buffer on behalf of another task.


Signed-off-by: Markus Metzger <[email protected]>
---

Index: git-tip/include/linux/mm.h
===================================================================
--- git-tip.orig/include/linux/mm.h 2009-03-23 16:23:19.000000000 +0100
+++ git-tip/include/linux/mm.h 2009-03-23 16:33:03.000000000 +0100
@@ -13,6 +13,7 @@
#include <linux/prio_tree.h>
#include <linux/debug_locks.h>
#include <linux/mm_types.h>
+#include <linux/sched.h>

struct mempolicy;
struct anon_vma;
@@ -1318,6 +1319,11 @@ void vmemmap_populate_print_last(void);

extern void *alloc_locked_buffer(size_t size);
extern void free_locked_buffer(void *buffer, size_t size);
-extern void release_locked_buffer(void *buffer, size_t size);
+extern void release_locked_buffer_on_behalf(struct mm_struct *mm,
+ void *buffer, size_t size);
+static inline void release_locked_buffer(void *buffer, size_t size)
+{
+ release_locked_buffer_on_behalf(current->mm, buffer, size);
+}
#endif /* __KERNEL__ */
#endif /* _LINUX_MM_H */
Index: git-tip/mm/mlock.c
===================================================================
--- git-tip.orig/mm/mlock.c 2009-03-23 16:23:19.000000000 +0100
+++ git-tip/mm/mlock.c 2009-03-23 16:24:24.000000000 +0100
@@ -660,16 +660,17 @@ void *alloc_locked_buffer(size_t size)
return buffer;
}

-void release_locked_buffer(void *buffer, size_t size)
+void release_locked_buffer_on_behalf(struct mm_struct *mm,
+ void *buffer, size_t size)
{
unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;

- down_write(&current->mm->mmap_sem);
+ down_write(&mm->mmap_sem);

- current->mm->total_vm -= pgsz;
- current->mm->locked_vm -= pgsz;
+ mm->total_vm -= pgsz;
+ mm->locked_vm -= pgsz;

- up_write(&current->mm->mmap_sem);
+ up_write(&mm->mmap_sem);
}

void free_locked_buffer(void *buffer, size_t size)
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


2009-03-27 14:25:58

by Oleg Nesterov

[permalink] [raw]
Subject: Re: [patch 2/14] x86, mm: add release_locked_buffer_on_behalf

On 03/27, Markus Metzger wrote:
>
> -void release_locked_buffer(void *buffer, size_t size)
> +void release_locked_buffer_on_behalf(struct mm_struct *mm,
> + void *buffer, size_t size)
> {
> unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;
>
> - down_write(&current->mm->mmap_sem);
> + down_write(&mm->mmap_sem);
>
> - current->mm->total_vm -= pgsz;
> - current->mm->locked_vm -= pgsz;
> + mm->total_vm -= pgsz;
> + mm->locked_vm -= pgsz;
>
> - up_write(&current->mm->mmap_sem);
> + up_write(&mm->mmap_sem);
> }

If you change this helper, perhaps you can remove the "void *buffer"
argument? It is not used. Actually, this helper should be renamed.
It doesn't free the memory, it only updates mm->xxx_vm.

Oleg.

2009-03-27 15:19:50

by Metzger, Markus T

[permalink] [raw]
Subject: RE: [patch 2/14] x86, mm: add release_locked_buffer_on_behalf

>-----Original Message-----
>From: Oleg Nesterov [mailto:[email protected]]
>Sent: Friday, March 27, 2009 3:22 PM
>To: Metzger, Markus T
>Cc: [email protected]; [email protected]; [email protected]; [email protected];
>[email protected]; [email protected]; [email protected]; Villacis, Juan;
>[email protected]
>Subject: Re: [patch 2/14] x86, mm: add release_locked_buffer_on_behalf
>
>On 03/27, Markus Metzger wrote:
>>
>> -void release_locked_buffer(void *buffer, size_t size)
>> +void release_locked_buffer_on_behalf(struct mm_struct *mm,
>> + void *buffer, size_t size)
>> {
>> unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;
>>
>> - down_write(&current->mm->mmap_sem);
>> + down_write(&mm->mmap_sem);
>>
>> - current->mm->total_vm -= pgsz;
>> - current->mm->locked_vm -= pgsz;
>> + mm->total_vm -= pgsz;
>> + mm->locked_vm -= pgsz;
>>
>> - up_write(&current->mm->mmap_sem);
>> + up_write(&mm->mmap_sem);
>> }
>
>If you change this helper, perhaps you can remove the "void *buffer"
>argument? It is not used. Actually, this helper should be renamed.
>It doesn't free the memory, it only updates mm->xxx_vm.

OK.

There's an alloc/free pair. This one is in between to allow another task to free
the buffer and get the memory correctly refunded.

How about refund_locked_buffer_memory(struct mm_struct *, size_t)?

regards,
markus.

---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.