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=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 0D418C433DF for ; Wed, 24 Jun 2020 21:02:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B4835207E8 for ; Wed, 24 Jun 2020 21:02:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C0Do7bcU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4835207E8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4400C6B0023; Wed, 24 Jun 2020 17:02:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F0096B0026; Wed, 24 Jun 2020 17:02:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DEF86B0027; Wed, 24 Jun 2020 17:02:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 127A06B0023 for ; Wed, 24 Jun 2020 17:02:22 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7FD868248068 for ; Wed, 24 Jun 2020 21:02:21 +0000 (UTC) X-FDA: 76965328482.05.sense17_3814b5326e47 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 60DEC1801DBEC for ; Wed, 24 Jun 2020 21:02:21 +0000 (UTC) X-HE-Tag: sense17_3814b5326e47 X-Filterd-Recvd-Size: 4916 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Wed, 24 Jun 2020 21:02:20 +0000 (UTC) Received: by mail-ej1-f65.google.com with SMTP id a1so3799587ejg.12 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=OHED42Ot5BazicmWzu/CMz7C1duwu3jYDUumAXRcSyFsOTJ5p00lQlfL+qKONVEtWX 93x6lHOi0jrWSWokDQ6nf57D9RQKbsnswgmAu4iskhoOGu879kcS9584fSDOum8cHUY3 gyVjK1wX8ejzN9Q5+9YKABEUHCCM0JA5YQ437Nx1wy8pKWKtDUwe3dpxAWX5YrUdvIbr JnbzzY6mAnUVC2j7z5NlFBsVXFe982u4szXiq3s/fep9tZVUydCkxK1cIVt5PxgpWjuQ bPhcvW7I4xt3ZCYCxmaTycxPGpySG1dZZnDwwNLpkqls/wqOlol1pRC6Aza59fpWLGcU WL3A== X-Gm-Message-State: AOAM530vEhVzopmmbisASnf3UMsr1CBylD4hryRvNdYdec8IxEN7NbL5 QD/VpXeRxZ+YksU8V7E7oTK1PyXUFD63wbzXvi1NuqxgXhg= X-Google-Smtp-Source: ABdhPJxMbkTVZFeqafVKJn8HY0wcCBMIsoXT8hVjSV2RB0oGms2P5ENEgkeFqhXyUNeyiMWdtYbU3LLL5pFCTAlnd2s= 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" X-Rspamd-Queue-Id: 60DEC1801DBEC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 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 > >