From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 997A2C433F5 for ; Thu, 23 Sep 2021 21:24:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FCE661242 for ; Thu, 23 Sep 2021 21:24:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2FCE661242 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A06646B006C; Thu, 23 Sep 2021 17:24:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B5006B0071; Thu, 23 Sep 2021 17:24:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A3A86B0073; Thu, 23 Sep 2021 17:24:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 7CEE16B006C for ; Thu, 23 Sep 2021 17:24:28 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 45D592D01D for ; Thu, 23 Sep 2021 21:24:28 +0000 (UTC) X-FDA: 78620117016.01.8770AEB Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP id DFA24600198A for ; Thu, 23 Sep 2021 21:24:27 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 8FD0F60F6D; Thu, 23 Sep 2021 21:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1632432266; bh=KnyKutFqoAJwR5PxeXhTE9a7a66eM57gSt+VwjBbwkU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=zCkdcbEgoqvuk+qfIW2/B5tKC4A4ZfwOYErSaEF9rzypQUPOQpRg7Ue5j622RyQJR FMFy5fQKfRE026MnISTuLuke+H2hgWeBNTj5D4p0s7NsF84WNQEAVrc0Yg6tr1fnGP +7Bp7GfdveYJ8oDHqLCILzej44+gALcnlIc4Eymw= Date: Thu, 23 Sep 2021 14:24:26 -0700 From: Andrew Morton To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko , Oscar Salvador , Zi Yan , Muchun Song , Naoya Horiguchi , David Rientjes , "Aneesh Kumar K . V" Subject: Re: [PATCH v2 1/4] hugetlb: add demote hugetlb page sysfs interfaces Message-Id: <20210923142426.8930bd1cfcabc782a2152c18@linux-foundation.org> In-Reply-To: <20210923175347.10727-2-mike.kravetz@oracle.com> References: <20210923175347.10727-1-mike.kravetz@oracle.com> <20210923175347.10727-2-mike.kravetz@oracle.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DFA24600198A X-Stat-Signature: 7ixdghm7zcck9ixu3t9jw7wac7ifrcrq Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=zCkdcbEg; spf=pass (imf14.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1632432267-935653 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 23 Sep 2021 10:53:44 -0700 Mike Kravetz wrote: > Two new sysfs files are added to demote hugtlb pages. These files are > both per-hugetlb page size and per node. Files are: > demote_size - The size in Kb that pages are demoted to. (read-write) > demote - The number of huge pages to demote. (write-only) > > By default, demote_size is the next smallest huge page size. Valid huge > page sizes less than huge page size may be written to this file. When > huge pages are demoted, they are demoted to this size. > > Writing a value to demote will result in an attempt to demote that > number of hugetlb pages to an appropriate number of demote_size pages. > > NOTE: Demote interfaces are only provided for huge page sizes if there > is a smaller target demote huge page size. For example, on x86 1GB huge > pages will have demote interfaces. 2MB huge pages will not have demote > interfaces. > > This patch does not provide full demote functionality. It only provides > the sysfs interfaces. > > It also provides documentation for the new interfaces. > > ... > > +static ssize_t demote_store(struct kobject *kobj, > + struct kobj_attribute *attr, const char *buf, size_t len) > +{ > + unsigned long nr_demote; > + unsigned long nr_available; > + nodemask_t nodes_allowed, *n_mask; > + struct hstate *h; > + int err; > + int nid; > + > + err = kstrtoul(buf, 10, &nr_demote); > + if (err) > + return err; > + h = kobj_to_hstate(kobj, &nid); > + > + /* Synchronize with other sysfs operations modifying huge pages */ > + mutex_lock(&h->resize_lock); > + > + 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. > + */ This comment doesn't become true until patch #4, and is a bit confusing in patch #1. Also, saying "the lock" is far less helpful than saying "hugetlb_lock"! > + 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); > + } > + > +out: > + spin_unlock_irq(&hugetlb_lock); How long can we spend with IRQs disabled here (after patch #4!)? > + mutex_unlock(&h->resize_lock); > + > + return len; > +} > +HSTATE_ATTR_WO(demote); > +