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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 78578C43461 for ; Thu, 1 Apr 2021 19:38:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 091C560725 for ; Thu, 1 Apr 2021 19:38:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 091C560725 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5B9ED6B00A0; Thu, 1 Apr 2021 15:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 592D36B00A3; Thu, 1 Apr 2021 15:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4830C6B00A4; Thu, 1 Apr 2021 15:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 281406B00A0 for ; Thu, 1 Apr 2021 15:38:24 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DE646DE1A for ; Thu, 1 Apr 2021 19:38:23 +0000 (UTC) X-FDA: 77984809686.28.D558EAC Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf02.hostedemail.com (Postfix) with ESMTP id CE94340002CF for ; Thu, 1 Apr 2021 19:38:20 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DA87360241; Thu, 1 Apr 2021 19:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617305897; bh=uOOaIddINYtFI1rB62AhT2r+hHCGkCQ7KIHGOn93qVY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HE+d3lJT+q/UdQqPV0y7CH5H2aEz1o2+8ke1WrJHNq4kI972+Yay1CfVIGhokWHyo XnNlRWlHo8uiHwXfZtohGfne5M0hwCsp4fbK8oODCpVxph0+6pkvo7LlRKQsWvbOu0 XtCAkqDccob/v5raqpLwS9pd2cstJZc52lGNeW34= Date: Thu, 1 Apr 2021 21:38:15 +0200 From: Greg KH To: Suren Baghdasaryan Cc: stable@vger.kernel.org, jannh@google.com, ktkhai@virtuozzo.com, torvalds@linux-foundation.org, shli@fb.com, namit@vmware.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Yang Shi , "Kirill A. Shutemov" , Hugh Dickins , Andrea Arcangeli , Christian Koenig , Claudio Imbrenda , Rik van Riel , Huang Ying , Minchan Kim , Andrew Morton Subject: Re: [PATCH 1/5] mm: reuse only-pte-mapped KSM page in do_wp_page() Message-ID: References: <20210401181741.168763-1-surenb@google.com> <20210401181741.168763-2-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210401181741.168763-2-surenb@google.com> X-Rspamd-Queue-Id: CE94340002CF X-Stat-Signature: fk6a9scypymdid9qpqsmgkyunk6h4jhm X-Rspamd-Server: rspam02 Received-SPF: none (linuxfoundation.org>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617305900-376420 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, Apr 01, 2021 at 11:17:37AM -0700, Suren Baghdasaryan wrote: > From: Kirill Tkhai > > Add an optimization for KSM pages almost in the same way that we have > for ordinary anonymous pages. If there is a write fault in a page, > which is mapped to an only pte, and it is not related to swap cache; the > page may be reused without copying its content. > > [ Note that we do not consider PageSwapCache() pages at least for now, > since we don't want to complicate __get_ksm_page(), which has nice > optimization based on this (for the migration case). Currenly it is > spinning on PageSwapCache() pages, waiting for when they have > unfreezed counters (i.e., for the migration finish). But we don't want > to make it also spinning on swap cache pages, which we try to reuse, > since there is not a very high probability to reuse them. So, for now > we do not consider PageSwapCache() pages at all. ] > > So in reuse_ksm_page() we check for 1) PageSwapCache() and 2) > page_stable_node(), to skip a page, which KSM is currently trying to > link to stable tree. Then we do page_ref_freeze() to prohibit KSM to > merge one more page into the page, we are reusing. After that, nobody > can refer to the reusing page: KSM skips !PageSwapCache() pages with > zero refcount; and the protection against of all other participants is > the same as for reused ordinary anon pages pte lock, page lock and > mmap_sem. > > [akpm@linux-foundation.org: replace BUG_ON()s with WARN_ON()s] > Link: http://lkml.kernel.org/r/154471491016.31352.1168978849911555609.stgit@localhost.localdomain > Signed-off-by: Kirill Tkhai > Reviewed-by: Yang Shi > Cc: "Kirill A. Shutemov" > Cc: Hugh Dickins > Cc: Andrea Arcangeli > Cc: Christian Koenig > Cc: Claudio Imbrenda > Cc: Rik van Riel > Cc: Huang Ying > Cc: Minchan Kim > Cc: Kirill Tkhai > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds > --- > include/linux/ksm.h | 7 +++++++ > mm/ksm.c | 30 ++++++++++++++++++++++++++++-- > mm/memory.c | 16 ++++++++++++++-- > 3 files changed, 49 insertions(+), 4 deletions(-) You forgot to put the git commit id of the upstream commit in here somewhere so we can properly reference it and track it. When/if you resend this, please add it to all of the commits. thanks, greg k-h