From patchwork Thu May 16 09:42:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10946173 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 9CE5413AD for ; Thu, 16 May 2019 09:42:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DEDF2896F for ; Thu, 16 May 2019 09:42:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82635289B8; Thu, 16 May 2019 09:42:49 +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 037E5289D4 for ; Thu, 16 May 2019 09:42:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A0486B0008; Thu, 16 May 2019 05:42:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 18E166B000A; Thu, 16 May 2019 05:42:44 -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 02E026B000C; Thu, 16 May 2019 05:42:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id A977D6B0008 for ; Thu, 16 May 2019 05:42:43 -0400 (EDT) Received: by mail-wm1-f71.google.com with SMTP id w9so571478wmc.5 for ; Thu, 16 May 2019 02:42:43 -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=QVnbcHKCSN58gborHO3ol7EK02u5KFHxun0EUOWl0vk=; b=Bz/BLjN0xQ9WFK7e5cH0tUG/xJBdFdiZgWWgWGOY/nv57ZC7XiLAi1vjpW08l3vTYj 4kt3o72Z1vlpphjRcAmiIBJhIzdhzysXSxoUc0tQ6W4h6qOKnN0HNpdSbInxl1b7rlVZ BLVbVVD80rfrmcN1Z8F/gtybSGD9vIoUxArR+43JH0nB9LYHre9jy4CGc8E6n5eKu2D7 GdTLrTGm02AotxKERfzQBqAkfedkkDEOn+Vn4XtIQrgOAg6CheTTgokGvAdvCr6oqihB Z1pZmue53DwwpezBCll+pc/0o9RxnYJucnHZyoI4x5bn5O5porZTAJ/hxJ53eZpwJN1k /rCQ== 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: APjAAAWi33PMSrjXCe+lpvq8pndpGB6RlTTqls308SvXyRhvQLHvBetL W1c7MjbBIkDIIY61v0gSey4qIPrKBnIkUl3XvvXgQzJnbnpVbkuzvqAvqyq2r+Udr+q8F4kLqNV 0XB77HUz97Y8oNrrlR8e7ZF7IApV2/0VAIvfUkLN5J1jpDdkUnuPBeLaN4T51hqEsFA== X-Received: by 2002:a1c:6586:: with SMTP id z128mr11441203wmb.67.1557999763221; Thu, 16 May 2019 02:42:43 -0700 (PDT) X-Received: by 2002:a1c:6586:: with SMTP id z128mr11441136wmb.67.1557999762047; Thu, 16 May 2019 02:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557999762; cv=none; d=google.com; s=arc-20160816; b=MW05nh/00nuPcYLDsou7bjzvgojnEjkrcwARubgX641ynjYo7X4jl3Fc5c/97eqOyW BClABGFvn9oKpix4j4Iv/ixK7uxN1WbqSCUJxkuf5L1ttdcJ4L0HsjGTk4zRxIvEaSGG S6XQuMWigBw/IND/pGyimueeBs6EKNxQrresgH+TPIyQoLpeQcNA8cdue/MYRapI6LsM jl2cSwAgZHf82/amkpF94MkllJDq04QDBajVUqHH9lrYjp5r8HdEPd03MAYaBMGQWtYY LhTd5KqQWSOeewckSd9yZ4YSOzVoMhNNBkRU4E8RGBKuoEUsPDCn8SD7FJDTejD8y9no pKpQ== 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=QVnbcHKCSN58gborHO3ol7EK02u5KFHxun0EUOWl0vk=; b=UvnnCLyJfUsGdrbyZCnqbDYsXpioJBskBIFu2S5nYPj7iZ2dNFbROo0B9qrKo/fEau Whc9I6I5qUhQdlEPUogtmLf41UHcWEFZKTmvfcnX7RsM9ZoN5tyNeIEqL78FcMRzXk3l kZC5ZWAXjBefJUQhAdpqY1aRfsffFnGMv9viIQN05JPmnRzcif7uDkV7m/HU3Vd9RrLa zyrchkSNaoHlbHESpmO7BkLdfTNvlivDXqdcp+fjsIJnDdChpBMySpZyfNN0jPELE3V9 +OCxbF/bpgyE7lfPgf0R52T5Txnh6v4NbLiPBK6Hf3sWs+ANZ1WZ5zWr9TGn4AZ99wRl N3jw== 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 x9sor3862542wrw.47.2019.05.16.02.42.41 for (Google Transport Security); Thu, 16 May 2019 02:42:42 -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: APXvYqwl58jVVB/evRftpSSgIkEdQu3pDWBXBnUiYvoeLvTMFHBb+KM6NeJY7cXdaHqSSVbMh3vTNg== X-Received: by 2002:a5d:6982:: with SMTP id g2mr13708219wru.223.1557999761707; Thu, 16 May 2019 02:42:41 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id n63sm4614805wmn.38.2019.05.16.02.42.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 May 2019 02:42:40 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Hugh Dickins , Alexey Dobriyan , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Greg KH , Suren Baghdasaryan , Minchan Kim , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org, linux-api@vger.kernel.org Subject: [PATCH RFC 3/5] mm/ksm: introduce ksm_madvise_unmerge() helper Date: Thu, 16 May 2019 11:42:32 +0200 Message-Id: <20190516094234.9116-4-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190516094234.9116-1-oleksandr@redhat.com> References: <20190516094234.9116-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 --- include/linux/ksm.h | 2 ++ mm/ksm.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index e824b3141677..a91a7cfc87a1 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -21,6 +21,8 @@ struct mem_cgroup; #ifdef CONFIG_KSM int ksm_madvise_merge(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long *vm_flags); +int ksm_madvise_unmerge(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long *vm_flags); int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); int __ksm_enter(struct mm_struct *mm); diff --git a/mm/ksm.c b/mm/ksm.c index 1fdcf2fbd58d..e0357e25e09f 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2478,6 +2478,25 @@ int ksm_madvise_merge(struct mm_struct *mm, struct vm_area_struct *vma, return 0; } +int ksm_madvise_unmerge(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_madvise_unmerge(vma, start, end, vm_flags); + if (err) + return err; break; }