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 B0F68C433F5 for ; Wed, 9 Mar 2022 18:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BE7A8D0002; Wed, 9 Mar 2022 13:03:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36D388D0001; Wed, 9 Mar 2022 13:03:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2355B8D0002; Wed, 9 Mar 2022 13:03:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 167748D0001 for ; Wed, 9 Mar 2022 13:03:05 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CE917A15F8 for ; Wed, 9 Mar 2022 18:03:04 +0000 (UTC) X-FDA: 79225619088.31.73CEE5A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf24.hostedemail.com (Postfix) with ESMTP id F27B3180029 for ; Wed, 9 Mar 2022 18:03:03 +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-out1.suse.de (Postfix) with ESMTPS id C2FA621118; Wed, 9 Mar 2022 18:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646848982; 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=LiWoSBzAEkCGU0Hf+4zaaFdMVIEVCG4nJJMVf7RzVoI=; b=CLLWUWSN9ubDbTFaYanIiR0lUrprKcnmy5k7Y81YBtZWKNgVMrYsWVqmZZVtHBhw45MIAg 78av96XmoTF3brhaxpSiGINy76V+yPR0uia/5I2xMZ7mA/EQohnmtLCU5VHL0hutHEFPeJ XAKwnxGZ29FZjSmq9+4fkUbJXqQxVHQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646848982; 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=LiWoSBzAEkCGU0Hf+4zaaFdMVIEVCG4nJJMVf7RzVoI=; b=Q3Obw1A7h7KfmsNKdz9yheW4tCJ3BjzF/XZHK6j4Wxtnm6t04z9OAuHCBvxAdEQ/5ksnOz M5yo065GDFt3twDw== 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 6897B13D7D; Wed, 9 Mar 2022 18:03:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ENrmGNbrKGIQJwAAMHmgww (envelope-from ); Wed, 09 Mar 2022 18:03:02 +0000 Message-ID: <62cd72d5-c072-d159-8de4-95cd0804c7db@suse.cz> Date: Wed, 9 Mar 2022 19:03:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v3 3/9] mm: slightly clarify KSM logic in do_swap_page() Content-Language: en-US To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , linux-mm@kvack.org References: <20220131162940.210846-1-david@redhat.com> <20220131162940.210846-4-david@redhat.com> From: Vlastimil Babka In-Reply-To: <20220131162940.210846-4-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: e7ukbwzti9piqhhc1afxsjnygdeshs9w Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=CLLWUWSN; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Q3Obw1A7; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Queue-Id: F27B3180029 X-HE-Tag: 1646848983-842784 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 1/31/22 17:29, David Hildenbrand wrote: > Let's make it clearer that KSM might only have to copy a page > in case we have a page in the swapcache, not if we allocated a fresh > page and bypassed the swapcache. While at it, add a comment why this is > usually necessary and merge the two swapcache conditions. > > Signed-off-by: David Hildenbrand Acked-by: Vlastimil Babka > --- > mm/memory.c | 38 +++++++++++++++++++++++--------------- > 1 file changed, 23 insertions(+), 15 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 923165b4c27e..3c91294cca98 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3615,21 +3615,29 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > goto out_release; > } > > - /* > - * Make sure try_to_free_swap or reuse_swap_page or swapoff did not > - * release the swapcache from under us. The page pin, and pte_same > - * test below, are not enough to exclude that. Even if it is still > - * swapcache, we need to check that the page's swap has not changed. > - */ > - if (unlikely((!PageSwapCache(page) || > - page_private(page) != entry.val)) && swapcache) > - goto out_page; > - > - page = ksm_might_need_to_copy(page, vma, vmf->address); > - if (unlikely(!page)) { > - ret = VM_FAULT_OOM; > - page = swapcache; > - goto out_page; > + if (swapcache) { > + /* > + * Make sure try_to_free_swap or reuse_swap_page or swapoff did > + * not release the swapcache from under us. The page pin, and > + * pte_same test below, are not enough to exclude that. Even if > + * it is still swapcache, we need to check that the page's swap > + * has not changed. > + */ > + if (unlikely(!PageSwapCache(page) || > + page_private(page) != entry.val)) > + goto out_page; > + > + /* > + * KSM sometimes has to copy on read faults, for example, if > + * page->index of !PageKSM() pages would be nonlinear inside the > + * anon VMA -- PageKSM() is lost on actual swapout. > + */ > + page = ksm_might_need_to_copy(page, vma, vmf->address); > + if (unlikely(!page)) { > + ret = VM_FAULT_OOM; > + page = swapcache; > + goto out_page; > + } > } > > cgroup_throttle_swaprate(page, GFP_KERNEL);