From patchwork Tue May 14 13:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10942983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F4D21398 for ; Tue, 14 May 2019 13:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E0C92850F for ; Tue, 14 May 2019 13:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 124CA2864B; Tue, 14 May 2019 13:17:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB9E02850F for ; Tue, 14 May 2019 13:17:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ABE56B000C; Tue, 14 May 2019 09:17:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 786BD6B000D; Tue, 14 May 2019 09:17:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5887A6B000E; Tue, 14 May 2019 09:17:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 058266B000C for ; Tue, 14 May 2019 09:17:02 -0400 (EDT) Received: by mail-wm1-f72.google.com with SMTP id 206so721279wmb.0 for ; Tue, 14 May 2019 06:17:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ljDEI5wRVFawwIewIlFmLcuWyWda410CfkNvL+gmA1U=; b=ar9PFyI7d5vEd7kTsfwOcJmSGp63MBOUbZZqM0ijBfz5cg5rJHyO/xWWScwwSQgCSz Wd2JlBYMIuvL1gR4GPSjljDZk2BkgVRzpj9ZT9Vl78L/4wz/VvIQGwVQzmq3sphFuCdQ T+p18rnBHICFTLmDNXxERulyS/MvFyN/nrTvc+EciW/637dxonto6iDQUF5936F1Tokm PBjq2RlCKZjZFZ9P9x4tsRoSkoEeZs5wtc/PGdThyJmR6QieQVfa5WIfbCFbDxYJY9qr tR35gZiwTev/1mD0uh1Y7dLjtQgG/0qfPCd28ki24EtHKSRYBlcmQJv8NS1TdK4OsF3g TETg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUmMdD8wuWCA3FBf3ETTMCR/ghH8jb+/N/jV0ccJGU1qiqO4ywe doLHrD5UrhnOkX4CXbLPxNSMDVLLbkSbMsAPCAWdbigYUsvwcGKBW/UuG63gFBo9yfabe2Mc4yw 8AUtKph1RvkQcD/CqBoMphfFLaSKTlRgka4Y47/YZ/QJNhyHff52RpsKdexBFRH8LOw== X-Received: by 2002:a05:6000:43:: with SMTP id k3mr21866914wrx.234.1557839821551; Tue, 14 May 2019 06:17:01 -0700 (PDT) X-Received: by 2002:a05:6000:43:: with SMTP id k3mr21866837wrx.234.1557839820039; Tue, 14 May 2019 06:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839820; cv=none; d=google.com; s=arc-20160816; b=avWBEnCxV/sKUdjq+5WXyLkGKrv6VxloW6aDyB4zkeR1V2gzh70zDQj6W6GdwOd2b2 6zZt77A1T8fNIxgWUXY0Hk3B8aUAbLikT/JCRM+C5Vkv4YVZ7/FQrDwlkjSyJxJyjYvK 7S8N7PWTrNoraxlOR6xgYpSVe2qwMBQ5t+2vdXZFQw6OW77kK3EaYe9irK3PKI645hVY qBNmsamMCL70xD5m9CQF+t6iuHAHq/2O+iO8UFypAwWhC/n3kMy4U6wxFvPg8WwGI+eD wYAIhMzbqaVh57Uqufjrq+PX7ukXIpzJNsypl6ou2vhi9RdnVQO1ZigJkuShK7VoqHd9 KlVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ljDEI5wRVFawwIewIlFmLcuWyWda410CfkNvL+gmA1U=; b=eSdrU7cRmT4rMLpXKbDxcg+Nh+FuKFAsJFKGQdb6n6Qbd/GmOqks3yccUvYGatVAbo 3tUlfl+y0B3KSQU2Krjr4FPmv1FWcWdic0TvFItaGBWDrxa1cBp5GK+VE9nL3Qs/Klow NXEr9L9rdxWCPx2U0HXE3piBjK8NkMSiZA9fGLQTQpQeAabcIZspjpe1f3gDKSvzLMSe Jp76I/YTr/BPu0IgNHiRG6OmBglRTUDr/I+oofLa6RPx6gKVujRYgGZ2oHjkSA52ZSlE dmhG31Zp5nA8FgRffj8Jt6mEIR4vpuBj4IvYBvO+quInx978bCsqHc5uLNx3qq+UCSfg udZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 91sor3120573wrk.4.2019.05.14.06.16.59 for (Google Transport Security); Tue, 14 May 2019 06:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: APXvYqyoalSThS0pSE7N8sUVpxlOVAILQIDieoXie4XGja4UBj+IPrLGODtVhuz+nrtZqWL+oyjzXQ== X-Received: by 2002:adf:b35e:: with SMTP id k30mr2739640wrd.178.1557839819722; Tue, 14 May 2019 06:16:59 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id u125sm7196076wme.15.2019.05.14.06.16.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:16:59 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org Subject: [PATCH RFC v2 2/4] mm/ksm: introduce ksm_leave() helper Date: Tue, 14 May 2019 15:16:52 +0200 Message-Id: <20190514131654.25463-3-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514131654.25463-1-oleksandr@redhat.com> References: <20190514131654.25463-1-oleksandr@redhat.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Move MADV_UNMERGEABLE part of ksm_madvise() into a dedicated helper since it will be further used for unmerging VMAs forcibly. This does not bring any functional changes. Signed-off-by: Oleksandr Natalenko --- mm/ksm.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 02fdbee394cc..e9f3901168bb 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2478,6 +2478,25 @@ static int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, return 0; } +static int ksm_leave(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long *vm_flags) +{ + int err; + + if (!(*vm_flags & VM_MERGEABLE)) + return 0; /* just ignore the advice */ + + if (vma->anon_vma) { + err = unmerge_ksm_pages(vma, start, end); + if (err) + return err; + } + + *vm_flags &= ~VM_MERGEABLE; + + return 0; +} + int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags) { @@ -2492,16 +2511,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, break; case MADV_UNMERGEABLE: - if (!(*vm_flags & VM_MERGEABLE)) - return 0; /* just ignore the advice */ - - if (vma->anon_vma) { - err = unmerge_ksm_pages(vma, start, end); - if (err) - return err; - } - - *vm_flags &= ~VM_MERGEABLE; + err = ksm_leave(vma, start, end, vm_flags); + if (err) + return err; break; }