lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <573d46b5-6285-0657-a729-3bfb0c2261ab@oracle.com>
Date:   Wed, 29 Sep 2021 12:34:10 -0700
From:   Mike Kravetz <mike.kravetz@...cle.com>
To:     David Hildenbrand <david@...hat.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Cc:     Michal Hocko <mhocko@...e.com>, Oscar Salvador <osalvador@...e.de>,
        Zi Yan <ziy@...dia.com>,
        Muchun Song <songmuchun@...edance.com>,
        Naoya Horiguchi <naoya.horiguchi@...ux.dev>,
        David Rientjes <rientjes@...gle.com>,
        "Aneesh Kumar K . V" <aneesh.kumar@...ux.ibm.com>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH v2 1/4] hugetlb: add demote hugetlb page sysfs interfaces

On 9/24/21 2:28 AM, David Hildenbrand wrote:
> On 23.09.21 19:53, Mike Kravetz wrote:
>> +    spin_lock_irq(&hugetlb_lock);
>> +    if (nid != NUMA_NO_NODE) {
>> +        nr_available = h->free_huge_pages_node[nid];
>> +        init_nodemask_of_node(&nodes_allowed, nid);
>> +        n_mask = &nodes_allowed;
>> +    } else {
>> +        nr_available = h->free_huge_pages;
>> +        n_mask = &node_states[N_MEMORY];
>> +    }
>> +    nr_available -= h->resv_huge_pages;
>> +    if (nr_available <= 0)
>> +        goto out;
>> +    nr_demote = min(nr_available, nr_demote);
>> +
>> +    while (nr_demote) {
>> +        if (!demote_pool_huge_page(h, n_mask))
>> +            break;
>> +
>> +        /*
>> +         * We may have dropped the lock in the routines to
>> +         * demote/free a page.  Recompute nr_demote as counts could
>> +         * have changed and we want to make sure we do not demote
>> +         * a reserved huge page.
>> +         */
>> +        nr_demote--;
>> +        if (nid != NUMA_NO_NODE)
>> +            nr_available = h->free_huge_pages_node[nid];
>> +        else
>> +            nr_available = h->free_huge_pages;
>> +        nr_available -= h->resv_huge_pages;
>> +        if (nr_available <= 0)
>> +            nr_demote = 0;
>> +        else
>> +            nr_demote = min(nr_available, nr_demote);
>> +    }
>>
> 
> Wonder if you could compress that quite a bit:
> 
> 
> ...
> spin_lock_irq(&hugetlb_lock);
> 
> if (nid != NUMA_NO_NODE) {
>     init_nodemask_of_node(&nodes_allowed, nid);
>     n_mask = &nodes_allowed;
> } else {
>     n_mask = &node_states[N_MEMORY];
> }
> 
> while (nr_demote) {
>     /*
>      * Update after each iteration because we might have temporarily
>      * dropped the lock and our counters changes.
>      */
>     if (nid != NUMA_NO_NODE)
>         nr_available = h->free_huge_pages_node[nid];
>     else
>         nr_available = h->free_huge_pages;
>     nr_available -= h->resv_huge_pages;
>     if (nr_available <= 0)
>         break;
>     if (!demote_pool_huge_page(h, n_mask))
>         break;
>     nr_demote--;
> };
> spin_unlock_irq(&hugetlb_lock);
> 
> Not sure if that "nr_demote = min(nr_available, nr_demote);" logic is really required. Once nr_available hits <= 0 we'll just stop denoting.
> 

No, it is not needed.  You suggested code looks much nicer.  I will
incorporate into the next version.

Thanks!
-- 
Mike Kravetz

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ