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 7F715C433FE for ; Wed, 5 Oct 2022 21:00:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2D956B0071; Wed, 5 Oct 2022 17:00:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB46F6B0073; Wed, 5 Oct 2022 17:00:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2DE06B0074; Wed, 5 Oct 2022 17:00:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A89966B0071 for ; Wed, 5 Oct 2022 17:00:37 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6A4A6405C5 for ; Wed, 5 Oct 2022 21:00:37 +0000 (UTC) X-FDA: 79988114514.02.27CEF66 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 03CE540017 for ; Wed, 5 Oct 2022 21:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665003636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bxjNtwOtJYr7Ap1Thb18UVXDvZENMtx4lxtXJfDuLn8=; b=eT/5nypuPOomML8eZjpp44Wr7DcIVCd/9dK6375Kyevndf/0Uf1e4nJer8ynHn6lO9DlB5 DQ9h4SDfL/OIsm+mJH/GVrpAdBJzNnOVNQvFvMm4VU7QdLgSBIXPDLzl7dllGY6UTN3XGm sYWVc1oOY2WRb7oxLcL1qf00WpNbK+Y= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-499-Z3rI3Sk7POynDBxfOcR8Fw-1; Wed, 05 Oct 2022 17:00:35 -0400 X-MC-Unique: Z3rI3Sk7POynDBxfOcR8Fw-1 Received: by mail-qk1-f199.google.com with SMTP id u6-20020a05620a430600b006e47fa02576so976261qko.22 for ; Wed, 05 Oct 2022 14:00:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=bxjNtwOtJYr7Ap1Thb18UVXDvZENMtx4lxtXJfDuLn8=; b=NG4D8OOKQm8lrWk4v32Ckl3YaGO45NruGs2mEZE3LylYac2PSS53rn/EYObkpZ+HEn u6XXkuPj8rxR2AUmOOBJlRr9Bd3DslY0GP1nwGl+mPsykAyjvuJgwat84JX6IMv1GVeZ R7KVrMWTy+n+6WUMDAWN1oTo4elX3JH29XxUi+3P3txH1ihMdHUaWSbi8WWqsm/cvCZz WgVSm+fy7LXGZ0G69xXoFVLBZqXGKgJdIxlYSTGpnjnyU5ul3RB4W4MyybUEc+TBBdIJ WtBW2zkyUsLOhbeBpbbJIF6F1sprNg+lv9EiptzvEBSoSmaSFbLjlzsyn3lqnJFxJJ00 xmZA== X-Gm-Message-State: ACrzQf2JK/cbCgUFMXGhpp9FMxUxM68NQSkLkmDu1+/V1th1kUdFSfAl biIw3a/9i3XUfyZpguPIjYPT8eEeNAyGOWthtRfxj2yOgWrygWbzs8+1anw3Jf5ME5iMzYWexkr 8nnOQ4Zi3Z84= X-Received: by 2002:a05:620a:22db:b0:6ce:4e82:5cc7 with SMTP id o27-20020a05620a22db00b006ce4e825cc7mr1023709qki.29.1665003634459; Wed, 05 Oct 2022 14:00:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WRvK3gEOhihmoFanKnOif3yzMLKCR7MYDIPihW7KP3HSKBLvonz45HUyg9WkbjDcr0jqQog== X-Received: by 2002:a05:620a:22db:b0:6ce:4e82:5cc7 with SMTP id o27-20020a05620a22db00b006ce4e825cc7mr1023685qki.29.1665003634222; Wed, 05 Oct 2022 14:00:34 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i25-20020ac84899000000b0039351b26714sm876918qtq.7.2022.10.05.14.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 14:00:33 -0700 (PDT) Date: Wed, 5 Oct 2022 17:00:32 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , "Matthew Wilcox (Oracle)" , Jason Gunthorpe , John Hubbard Subject: Re: [PATCH v1 6/7] mm/ksm: convert break_ksm() to use walk_page_range_vma() Message-ID: References: <20220930141931.174362-1-david@redhat.com> <20220930141931.174362-7-david@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220930141931.174362-7-david@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665003637; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bxjNtwOtJYr7Ap1Thb18UVXDvZENMtx4lxtXJfDuLn8=; b=r2tqWRkSs9RUauliSigEU+60FFliEAHwledrDHJGbHWu3NVShQfdyln4lP0nM7D1BbxUXD 5AbCdLkWaeQqjzEpDzEmL2xBLOEtIt3dtGVc5VHp3yHvtMrl6toSyxpBtY/W7IjqmjFWql KuoOeIE0JkzAPtrMO08rNw1SZIgdE7I= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="eT/5nypu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665003637; a=rsa-sha256; cv=none; b=CG87ldXOYYOgCz+B344dt0XUKM/k0nnS7mctRf4xLA7c5RBynPliFqVhdq1pNk6D7OiBPS RLJJQKhOr2U8+WuinCkun/1KxkSCmwArTYFbOT7K82ow3LdZLRk/8DVDjBvKNXslnxgbsx t3/zk0N2mMe7oUl24rkJZQd5E0pSTBM= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 03CE540017 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="eT/5nypu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: 8tr4wmj9n57i6utuaau69z7k9zmdp13x X-HE-Tag: 1665003636-75568 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 Fri, Sep 30, 2022 at 04:19:30PM +0200, David Hildenbrand wrote: > FOLL_MIGRATION exists only for the purpose of break_ksm(), and > actually, there is not even the need to wait for the migration to > finish, we only want to know if we're dealing with a KSM page. > > Using follow_page() just to identify a KSM page overcomplicates GUP > code. Let's use walk_page_range_vma() instead, because we don't actually > care about the page itself, we only need to know a single property -- > no need to even grab a reference on the page. > > In my setup (AMD Ryzen 9 3900X), running the KSM selftest to test unmerge > performance on 2 GiB (taskset 0x8 ./ksm_tests -D -s 2048), this results in > a performance degradation of ~4% (old: ~5010 MiB/s, new: ~4800 MiB/s). > I don't think we particularly care for now. > > Signed-off-by: David Hildenbrand [...] > +int break_ksm_pud_entry(pud_t *pud, unsigned long addr, unsigned long next, > + struct mm_walk *walk) > +{ > + /* We only care about page tables to walk to a single base page. */ > + if (pud_leaf(*pud) || !pud_present(*pud)) > + return 1; > + return 0; > +} Is this needed? I thought the pgtable walker handlers this already. [...] > static int break_ksm(struct vm_area_struct *vma, unsigned long addr) > { > - struct page *page; > vm_fault_t ret = 0; > > + if (WARN_ON_ONCE(!IS_ALIGNED(addr, PAGE_SIZE))) > + return -EINVAL; > + > do { > bool ksm_page = false; > > cond_resched(); > - page = follow_page(vma, addr, > - FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE); > - if (IS_ERR_OR_NULL(page)) > - break; > - if (PageKsm(page)) > - ksm_page = true; > - put_page(page); > + ret = walk_page_range_vma(vma, addr, addr + PAGE_SIZE, > + &break_ksm_ops, &ksm_page); > + if (WARN_ON_ONCE(ret < 0)) > + return ret; I'm not sure this would be worth it, especially with a 4% degrade. The next patch will be able to bring 50- LOC, but this patch does 60+ anyway, based on another new helper just introduced... I just don't see whether there's strong enough reason to do so to drop FOLL_MIGRATE. It's different to the previous VM_FAULT_WRITE refactor because of the unshare approach was much of a good reasoning to me. Perhaps I missed something? -- Peter Xu