Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp924596ybt; Wed, 24 Jun 2020 15:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYwCnN4BV/KQW5gEa72paIOauUswU80gd8QVAl0Ev37Wd4RhEKsKN6ZyORXrgzijGNoOXZ X-Received: by 2002:a17:907:429b:: with SMTP id ny19mr7908140ejb.498.1593036042953; Wed, 24 Jun 2020 15:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593036042; cv=none; d=google.com; s=arc-20160816; b=rBxbZmtCMIj24Fbwr4Is3dJEcriiornieX2CMfAvW7VFUj8Tv/BHVc0UsIpIrfX8Hu Pe708BwhUvjMs9Z9t3MO9KT15zQnayGe1pbNE7lpgtfdG282m0KU5FOqOoHhpQsokOCH CfuhIijmi8Fn3qlKN8VLq27yZDVXOWizrwfKnaI98bt7RxWoWoW1P0OoyTd8VUItzOjY YTIuauxJSuW+RVP8XRDd7bJc7ffV7JacMMUHQ7olyha9EZc/GgDDx/ybgQ4ghFgjLGLP v0GToXy4ZrFXxxUjJqQmN6QX/A7ZbJCrU8nvjqV4ZhQrcBBaus3H+XrO5iQEYOJxhQX6 xJng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Q65HneRMVLhdg5SVAjawRKs3e4Na9FxPWBLgo8PD4DM=; b=yNvnne5JCehLBMBjdArBliz2AsoatZ06tS18TVGIj3x4/gUo2SL0hF4SZk75DRLX8b nkNffXrjjPWYfKWTClKrZfl4gSQPlLKoH0rGaOXpYxMKq2JRGjtK4KnhV5VqqRE2h9QN VHcRWoESevgRp2hdTvtboqSWdROir6EqtEkQTTb/8aJ9j1sQcsYlGKU0UMgOCf1Xsb/Z Tb+5Ux7VAsRLIugr8SV5h7glRbEOxuJickvXQy9CYav4UGTxkSdXwuUOpibosS2KqtOo FbhX9Gzh6zGVIiHgkUx62SyHvDUmblIEl2YeFLN2Bi6fDwRvvyULSSL4vOvbGPel+1oy zqaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C0Do7bcU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn15si5734161ejb.513.2020.06.24.15.00.19; Wed, 24 Jun 2020 15:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C0Do7bcU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389097AbgFXVCW (ORCPT + 99 others); Wed, 24 Jun 2020 17:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388770AbgFXVCV (ORCPT ); Wed, 24 Jun 2020 17:02:21 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05346C061573 for ; Wed, 24 Jun 2020 14:02:21 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id y10so3861504eje.1 for ; Wed, 24 Jun 2020 14:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Q65HneRMVLhdg5SVAjawRKs3e4Na9FxPWBLgo8PD4DM=; b=C0Do7bcUEx1h891atQwx7sZfQK/co/oG5+keMt+dphDsjEoV7ElA4VRaEUwwl2WyPx jHFcXosSdWbwdjNXrPQxg54FGXbeidn6T6UwSBKPV2zT/kEGYOLm5PlqKumfRtYP19XB 0J/jcMXrC4Bvk7fpoY5iO0GjQIkfjaxC6VxlizzfQF+Y9EcaBcxNMfroMIR9v5Ekv71/ lqrH5fypCSpjQRp6EM5ptJLlTafD3hlK1WfBrk2cGJTLj00RpS7NPn+q2RVmbQCAq1y4 jAV+g8VmpC+rw49LdR13HpfUq3/5A0BanSQd8KUpiKvr3x+RuDFX8cl8khwrrvvTC7SR MVNA== 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=Q65HneRMVLhdg5SVAjawRKs3e4Na9FxPWBLgo8PD4DM=; b=F08eJaDhleu8g/TZZJ8oX/ZDSIsiitDzbiZuEgFx95cpU0PUiXhpwWqY5NHleKDKue vvMEp6Tjs41Ksp4BqCqQd0xt7oWxWHzUIObH4AbKCBvrjIUdWVmzqxgsTWEZJPGbq4Fh iD0rCEpCU7Ej5frK9ugYzASA9Su6O6Pn8wO/WPaSHaY2Evx3JHkYh9jy1AdAT3lduly2 e9gStrmmNlYI62K1NmBpFqpMBSZeeixABDTFnvkNB4ArcSJl/UyGdQ59e8UR5zyKE7nh lHQF+LtINxfaGMzR4SfbXMymMnJi93wgPzpNdFBmnbtB69GlFMePyGvl54GddeJpJpvX dI7A== X-Gm-Message-State: AOAM532h+1nBj3XOPDHtZW7b6lXidCou7TN4K9VvGBIRuj7u3ZtOhH02 JlTyW6gitW0O+XI95yTEioErjJ6lXSEB//XKGR8= X-Received: by 2002:a17:906:7751:: with SMTP id o17mr28009624ejn.111.1593032539710; Wed, 24 Jun 2020 14:02:19 -0700 (PDT) MIME-Version: 1.0 References: <20200624191417.16735-1-chris@chris-wilson.co.uk> <20200624192116.GO6578@ziepe.ca> In-Reply-To: From: Yang Shi Date: Wed, 24 Jun 2020 14:02:07 -0700 Message-ID: Subject: Re: [PATCH] mm: Skip opportunistic reclaim for dma pinned pages To: Jason Gunthorpe Cc: Chris Wilson , Linux MM , Linux Kernel Mailing List , intel-gfx@lists.freedesktop.org, Andrew Morton , Jan Kara , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Claudio Imbrenda , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 24, 2020 at 1:23 PM Yang Shi wrote: > > On Wed, Jun 24, 2020 at 12:21 PM Jason Gunthorpe wrote: > > > > On Wed, Jun 24, 2020 at 08:14:17PM +0100, Chris Wilson wrote: > > > A general rule of thumb is that shrinkers should be fast and effective. > > > They are called from direct reclaim at the most incovenient of times when > > > the caller is waiting for a page. If we attempt to reclaim a page being > > > pinned for active dma [pin_user_pages()], we will incur far greater > > > latency than a normal anonymous page mapped multiple times. Worse the > > > page may be in use indefinitely by the HW and unable to be reclaimed > > > in a timely manner. > > > > A pinned page can't be migrated, discarded or swapped by definition - > > it would cause data corruption. > > > > So, how do things even get here and/or work today at all? I think the > > explanation is missing something important. > > The __remove_mapping() will try to freeze page count if the count is > expected otherwise just not discard the page. I'm not quite sure why > the check is done that late, my wild guess is to check the refcount at > the last minute so there might be a chance the pin gets released right > before it. > > But I noticed a bug in __remove_ampping() for THP since THP's dma > pinned count is recorded in the tail page's hpage_pinned_refcount > instead of refcount. So, the refcount freeze might be successful for > pinned THP. Chris's patch could solve this issue too, but I'm not This bug is not valid. I just realized try_grab_page() would increase both refcount and hpage_pinned_refcount. > sure if it is worth backing earlier once dma pinned page is met. If it > is worth, the follow-up question is why not just skip such page in > scan phase? > > > > > Jason > >