Re: [RFC] mm: generic adaptive large memory allocation APIs

From: Changli Gao
Date: Wed May 05 2010 - 23:22:35 EST


2010/5/6 Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>:
> Changli Gao wrote:
>> struct kvfree_work_struct {
>>    struct work_struct   Âwork;
>>    void          Â*head;
>>    void          Â**ptail;
>> };
>
> I wonder why "struct kvfree_work_struct" is needed.
> According to http://kernel.ubuntu.com/git?p=jj/ubuntu-lucid.git;a=blobdiff;f=security/apparmor/match.c;h=d2cd55419acfcae85cb748c8f837a4384a3a0d29;hp=afc2dd2260edffcf88521ae86458ad03aa8ea12c;hb=f5eba4b0a01cc671affa429ba1512b6de7caeb5b;hpb=abdff9ddaf2644d0f9962490f73e030806ba90d3 ,
>
> static void kvfree_work(struct work_struct *work)
> {
> Â Â Â Âvfree(work);
> }
>
> void kvfree_inatomic(void *ptr, size_t size)
> {
> Â Â Â Âif (size < PAGE_SIZE) {
> Â Â Â Â Â Â Â Âkfree(ptr);
> Â Â Â Â} else if (is_vmalloc_addr(ptr)) {
> Â Â Â Â Â Â Â Â/*
> Â Â Â Â Â Â Â Â * We can embed "struct work_struct" inside *ptr
> Â Â Â Â Â Â Â Â * because size >= PAGE_SIZE.
> Â Â Â Â Â Â Â Â */
> Â Â Â Â Â Â Â Âstruct work_struct *work = ptr;
> Â Â Â Â Â Â Â ÂBUILD_BUG_ON(sizeof(struct work_struct) > PAGE_SIZE);
> Â Â Â Â Â Â Â ÂINIT_WORK(&work, kvfree_work);
> Â Â Â Â Â Â Â Âschedule_work(&work);

&work should be work. It is a much better idea. thanks very much.

> Â Â Â Â} else {
> Â Â Â Â Â Â Â Âfree_pages_exact(ptr, size);
> Â Â Â Â}
> }
>
> should do what you want. (Though, I didn't test it.)
>

--
Regardsï
Changli Gao(xiaosuo@xxxxxxxxx)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/