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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, 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,USER_IN_DEF_DKIM_WL autolearn=ham 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 164C9C433ED for ; Thu, 1 Apr 2021 19:47:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81D7A610A5 for ; Thu, 1 Apr 2021 19:47:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81D7A610A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 02E316B00A5; Thu, 1 Apr 2021 15:47:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF95D6B00A7; Thu, 1 Apr 2021 15:47:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4B956B00A8; Thu, 1 Apr 2021 15:47:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id B0E4C6B00A5 for ; Thu, 1 Apr 2021 15:47:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 68343183C780C for ; Thu, 1 Apr 2021 19:47:25 +0000 (UTC) X-FDA: 77984832450.30.C99EFAC Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf03.hostedemail.com (Postfix) with ESMTP id A54EDC0001FE for ; Thu, 1 Apr 2021 19:47:23 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id w8so2971499ybt.3 for ; Thu, 01 Apr 2021 12:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=apM991fcSzCvxwtBXbERhXcPo06u2NcSXVhXFrtKV00=; b=TJ6yRcs7/F+2BvmvNKprIwFoMgYMbWh480ndLABBp0juXVh2ZGBUuvuz1buktyB14w 7xq89lWufQjLlBuXpCHyqUGBObvQQzPVEYMOlCYzSbyciFwTo68cjXK6zV6g8VyMSsPA PFhlsU9toLUL7vPMG9GtOe2iJpR7dFGkxOEQtH4ppukpLl+d8bcFOV71LOQzVf69KHCb PZZ5ueSMNHPrvgcEfVfSff1dRpbMXnBriAiJDO02/3NMRRmTBs4rr7WgQJw82o7WX8q2 e6e4ie7dVH+3dYBbfmQqMQnFY433jTjVp/LHXLPzINeg3jvPjoV34mui1dgOJgg2ECj+ 4kKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=apM991fcSzCvxwtBXbERhXcPo06u2NcSXVhXFrtKV00=; b=aqruf9PgNg9e6gbg3k4P5OuIQXFX+gYorEAyiI7Pxf7Z9+uRrUm2pWmquIpLlcGG1g TlME9/DChvFwha4mb1Vy926ynwgT5MRgJNBeedQ354F4RcXWj8LfKIGE3PSyn5spnJYB 5YS0OHCeJxmqE/LhpqLOU5a6b/n388gbBSVFNjImugYOC46MMIHtAHQp/vpCGS9+mqCI 9i8NR3Fa7ZyfrrQmHAj78qVD6z0uiAZu0s6DRYcm19cfleLTxULC31cJ6r3q6AEF8heP 0TRGlphpeKg4BUfKhMTafL/yxg8FUk61jQ3kw3zf3fTf19o61x026g9IwU1nMg1L5XKP ojKw== X-Gm-Message-State: AOAM533sMMJj6DvbLcsb2v3oh++hL/jilELsJGKu3sknCOLuiOxpGU8q gu7AEpNDQ3kC+R5FtLgezJKVDpT66f/YwIXaBxM/Qg== X-Google-Smtp-Source: ABdhPJyq6aKnmG2A7Si4ZLOB+gj583IhyHClIDbpZy/gCj/QYdL7b4iuDo+gvH4J2QHnLDJF4hzy7NNomu+zV265/hw= X-Received: by 2002:a25:c801:: with SMTP id y1mr14487864ybf.250.1617306444108; Thu, 01 Apr 2021 12:47:24 -0700 (PDT) MIME-Version: 1.0 References: <20210401181741.168763-1-surenb@google.com> <20210401181741.168763-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 1 Apr 2021 12:47:13 -0700 Message-ID: Subject: Re: [PATCH 1/5] mm: reuse only-pte-mapped KSM page in do_wp_page() To: Greg KH Cc: stable , Jann Horn , Kirill Tkhai , Linus Torvalds , Shaohua Li , Nadav Amit , linux-mm , LKML , kernel-team , Yang Shi , "Kirill A. Shutemov" , Hugh Dickins , Andrea Arcangeli , Christian Koenig , Claudio Imbrenda , Rik van Riel , Huang Ying , Minchan Kim , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: ejcgjopd1iogzxrbz1bkh939je9nhxqd X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A54EDC0001FE Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-yb1-f181.google.com; client-ip=209.85.219.181 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617306443-950544 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 1, 2021 at 12:38 PM Greg KH wrote: > > 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. Will do. Thanks! > > thanks, > > greg k-h