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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03B5CC433EF for ; Fri, 11 Feb 2022 12:27:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 629116B0078; Fri, 11 Feb 2022 07:27:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B2696B007B; Fri, 11 Feb 2022 07:27:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452906B007D; Fri, 11 Feb 2022 07:27:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2F7206B0078 for ; Fri, 11 Feb 2022 07:27:30 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CEFF0181AC9C6 for ; Fri, 11 Feb 2022 12:27:29 +0000 (UTC) X-FDA: 79130424618.28.3767EA9 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf20.hostedemail.com (Postfix) with ESMTP id 3DF0A1C0002 for ; Fri, 11 Feb 2022 12:27:29 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D3E291F3A2; Fri, 11 Feb 2022 12:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1644582447; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OMTT5iiyjFVPOD3au65s1i3U4tMtMbGOAoi81BKHy10=; b=n/nMaDalA292S13jD0IMDYqoNMoH9n8kldxKj7r9fxHjM/49sIcbCFDArZFVr2CJDyZZ+g R3AqvsZNUVKj9icpY97GAf7Uu3RRK66wSs7IXbeduQ1HoPBsKX/wOO92CFS6GOZMJUDjs8 vCVrBLQhdCoEmCOyRp7LtZFEnIOia1c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1644582447; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OMTT5iiyjFVPOD3au65s1i3U4tMtMbGOAoi81BKHy10=; b=S/YLpLRl7YBreu/bCwbF4OgqcJW6FYEUtlo0MjGKVHUvufGvWyvWVRc/ceEcpyHCxP45gg IF206xDiQWhlJcBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9974613C6D; Fri, 11 Feb 2022 12:27:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6AjUJC9WBmIbbgAAMHmgww (envelope-from ); Fri, 11 Feb 2022 12:27:27 +0000 Message-ID: <826e69d0-c81c-06c1-c675-b54bd4557ff3@suse.cz> Date: Fri, 11 Feb 2022 13:27:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Content-Language: en-US To: Hugh Dickins , Andrew Morton Cc: Michal Hocko , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> <3d204af4-664f-e4b0-4781-16718a2efb9c@google.com> From: Vlastimil Babka Subject: Re: [PATCH 06/13] mm/munlock: maintain page->mlock_count while unevictable In-Reply-To: <3d204af4-664f-e4b0-4781-16718a2efb9c@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3DF0A1C0002 X-Stat-Signature: crrquqhswqw1jgr8m4epwwkiiswhkhya Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="n/nMaDal"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="S/YLpLRl"; dmarc=none; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-HE-Tag: 1644582449-560337 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 2/6/22 22:40, Hugh Dickins wrote: > Previous patches have been preparatory: now implement page->mlock_count. > The ordering of the "Unevictable LRU" is of no significance, and there is > no point holding unevictable pages on a list: place page->mlock_count to > overlay page->lru.prev (since page->lru.next is overlaid by compound_head, > which needs to be even so as not to satisfy PageTail - though 2 could be > added instead of 1 for each mlock, if that's ever an improvement). > > But it's only safe to rely on or modify page->mlock_count while lruvec > lock is held and page is on unevictable "LRU" - we can save lots of edits > by continuing to pretend that there's an imaginary LRU here (there is an > unevictable count which still needs to be maintained, but not a list). > > The mlock_count technique suffers from an unreliability much like with > page_mlock(): while someone else has the page off LRU, not much can > be done. As before, err on the safe side (behave as if mlock_count 0), > and let try_to_unlock_one() move the page to unevictable if reclaim finds > out later on - a few misplaced pages don't matter, what we want to avoid > is imbalancing reclaim by flooding evictable lists with unevictable pages. > > I am not a fan of "if (!isolate_lru_page(page)) putback_lru_page(page);": > if we have taken lruvec lock to get the page off its present list, then > we save everyone trouble (and however many extra atomic ops) by putting > it on its destination list immediately. Good point. > Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka > --- > include/linux/mm_inline.h | 11 +++++-- > include/linux/mm_types.h | 19 +++++++++-- > mm/huge_memory.c | 5 ++- > mm/memcontrol.c | 3 +- > mm/mlock.c | 68 +++++++++++++++++++++++++++++++-------- > mm/mmzone.c | 7 ++++ > mm/swap.c | 1 + > 7 files changed, 92 insertions(+), 22 deletions(-) > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > index b725839dfe71..884d6f6af05b 100644 > --- a/include/linux/mm_inline.h > +++ b/include/linux/mm_inline.h > @@ -99,7 +99,8 @@ void lruvec_add_folio(struct lruvec *lruvec, struct folio *folio) > > update_lru_size(lruvec, lru, folio_zonenum(folio), > folio_nr_pages(folio)); > - list_add(&folio->lru, &lruvec->lists[lru]); > + if (lru != LRU_UNEVICTABLE) > + list_add(&folio->lru, &lruvec->lists[lru]); > } > > static __always_inline void add_page_to_lru_list(struct page *page, > @@ -115,6 +116,7 @@ void lruvec_add_folio_tail(struct lruvec *lruvec, struct folio *folio) > > update_lru_size(lruvec, lru, folio_zonenum(folio), > folio_nr_pages(folio)); > + /* This is not expected to be used on LRU_UNEVICTABLE */ Felt uneasy about this at first because it's just a _tail version of lruvec_add_folio, and there's probably nothing fundamental about the users of _tail to not encounter unevictable pages. But if the assumption is ever violated, the poisoned list head should make it immediately clear, so I guess that's fine. > list_add_tail(&folio->lru, &lruvec->lists[lru]); > } > > @@ -127,8 +129,11 @@ static __always_inline void add_page_to_lru_list_tail(struct page *page, > static __always_inline > void lruvec_del_folio(struct lruvec *lruvec, struct folio *folio) > { > - list_del(&folio->lru); > - update_lru_size(lruvec, folio_lru_list(folio), folio_zonenum(folio), > + enum lru_list lru = folio_lru_list(folio); > + > + if (lru != LRU_UNEVICTABLE) > + list_del(&folio->lru); > + update_lru_size(lruvec, lru, folio_zonenum(folio), > -folio_nr_pages(folio)); > } >