Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp263828pxb; Wed, 14 Apr 2021 14:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkpRza5ihc1WknPdVJL291Q+hsu0b6NbqFkz/q6svcxPoR4wqeS1/fREh9eB2epvW0G1Dj X-Received: by 2002:a17:906:170a:: with SMTP id c10mr160194eje.493.1618437580879; Wed, 14 Apr 2021 14:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618437580; cv=none; d=google.com; s=arc-20160816; b=eVquAJnMsHjvSoDPjGBMNQIJkltOwRwij/TraaZlfMCYkmj0Rg8VtbV33FD5MTNvL6 podQqCHvxAfWb8l6wpy34JJldzPkXJP1BEcN1I280/u7S9B9Dpcq/iZwT8D4AIIpKw8/ CDJSmOnx/0V2BeEV78UZvTjwoSBbJ6hmuz1aEE5Vgre21V0Xi9tqenO12PW4Lpd0Lxhu eoD9AP/uX9/5/9MSWwDTt72jucFn6P3oiZs3e437fefk9lG222t8ZusLF97x4t6BuxlH SpPKbaZpkjr3gCh7xaMaIWj75HCBDDpp2LF8Be+M0Y/PgRPPyWtcHieARDujrcmzGJ7C EBCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PiBo43OFru+bDu0uJ6yuLMmVjzq0Az7R5lB0fiAm//I=; b=zOT75c+SWb/jmGdYS5zU9y1gmTM04DIz/PwfZyNSnRDNK3ns3KJFxqx1ZKS1xvsrQB TeORhDkjY7Wtc2U1bGCB751+EM+uqefFBWiXJ6Vk80NXlJwO5SuqRdfD2qGZDNAdhEWK ch0wTK3Lp5sEAtDFhs884luYsdYMmE8DJF0KYzrzEHIe9he1AupHwfJUhZDWghCC2BFP b1vw+xheXA9JQT7LbZGGTnYNFjAcdqS5ymA3pH5y5QcthzTyDPDZpn3WShU/SBJIX5AT rDUPlb/lXiSowtcDVxSZfFxSyhF37zIrQLzbkU24SkHYJiCmzJNmfwYUenzXTLuZNr+5 BkZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XTy+w1bU; 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 h20si703773ede.157.2021.04.14.14.58.32; Wed, 14 Apr 2021 14:59:40 -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=XTy+w1bU; 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 S1350153AbhDNIic (ORCPT + 99 others); Wed, 14 Apr 2021 04:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350151AbhDNIiV (ORCPT ); Wed, 14 Apr 2021 04:38:21 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85241C061574 for ; Wed, 14 Apr 2021 01:37:58 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id a2-20020a0568300082b029028d8118b91fso188613oto.2 for ; Wed, 14 Apr 2021 01:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PiBo43OFru+bDu0uJ6yuLMmVjzq0Az7R5lB0fiAm//I=; b=XTy+w1bUUAQFN9swD0nRJtOWVb602f1PClQTxXfmtBVhcW9gBfZBTW8fdG6scCucET CgcpWCAWbeprQUSRVGX9E104UzoreACyFgyh32CjIvSxuQC1SR2fiBAnUFX1/AgpFfYr Qhny1WJ50LIoboImNyPOyT1II5zFs7N8uicLZKgkxGktrbim4gQlbwqXDkg1xrGdMROC lTaM1QkHXEEySKBsoTf/RWvqse0Zh7peEOtU+wIX47OVCveLe2XWFgS41SWhdnGSV3p2 bhRDqTApd70l5iQ1Vw2+wLYtPR22DJF1whtxHokp2YdnOKzRh22X5NMVWzYOYBYiarFp +cIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PiBo43OFru+bDu0uJ6yuLMmVjzq0Az7R5lB0fiAm//I=; b=kTJJhu95LU713VwUAvwE7VH5m6ezqULAO+P9iHZnQ6CvA+DH1/2UadrE8r9zeo36H4 vHcCi/yRrtJ3XPJnv3E6GHCGrjaxcIbC4c8EKgpk9qjMfaOHB32qpLG+LIxfs8bVIqWR MwSUV6fINsQVmxor6fA+MNZIPetu8l727Y4IbMdvKHVoLUz8VRvDZoTexGxHao1ks4jy 23EQ0HpzoTypgbbVWVakuRKT60A7CVdJENpUkeIwmmYyzEJIXwFOy5b5RTVguGQwzYJB GKh+/HRSdanoUS5GXeP/xpx3KC4soIQrdCjtuy0exPoRyYUwyFBTreb1czNFDSXOd08O lhfA== X-Gm-Message-State: AOAM533WzFz5Ir2q4YzIwsJhRn9qo4zh+5ooXZZHjz07+z90Apv9tG/p aYQulIIqJZ0tD3/9eNGvBEg= X-Received: by 2002:a05:6830:2117:: with SMTP id i23mr10450350otc.331.1618389477980; Wed, 14 Apr 2021 01:37:57 -0700 (PDT) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id r19sm284616oie.58.2021.04.14.01.37.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Apr 2021 01:37:57 -0700 (PDT) From: Yafang Shao To: bsingharora@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yafang Shao , Tejun Heo , Josh Snyder Subject: [PATCH] delayacct: clear right task's flag after blkio completes Date: Wed, 14 Apr 2021 16:37:20 +0800 Message-Id: <20210414083720.24083-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When I was implementing a latency analyze tool by using task->delays and other things, I found there's issue in delayacct. The issue is it should clear the target's flag instead of current's in delayacct_blkio_end(). When I git blame delayacct, I found there're some similar issues we have fixed in delayacct_blkio_end(). 'Commit c96f5471ce7d ("delayacct: Account blkio completion on the correct task")' fixed the issue that it should account blkio completion on the target task instead of current. 'Commit b512719f771a ("delayacct: fix crash in delayacct_blkio_end() after delayacct init failure")' fixed the issue that it should check target task's delays instead of current task'. It seems that delayacct_blkio_{begin, end} are error prone. So I introduce a new paratmeter - the target task 'p' into these helpers, after that change, the callsite will specifilly set the right task, which should make it less error prone. Signed-off-by: Yafang Shao Cc: Tejun Heo Cc: Josh Snyder --- include/linux/delayacct.h | 20 ++++++++++---------- mm/memory.c | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h index 2d3bdcccf5eb..21651f946751 100644 --- a/include/linux/delayacct.h +++ b/include/linux/delayacct.h @@ -82,16 +82,16 @@ static inline int delayacct_is_task_waiting_on_io(struct task_struct *p) return 0; } -static inline void delayacct_set_flag(int flag) +static inline void delayacct_set_flag(struct task_struct *p, int flag) { - if (current->delays) - current->delays->flags |= flag; + if (p->delays) + p->delays->flags |= flag; } -static inline void delayacct_clear_flag(int flag) +static inline void delayacct_clear_flag(struct task_struct *p, int flag) { - if (current->delays) - current->delays->flags &= ~flag; + if (p->delays) + p->delays->flags &= ~flag; } static inline void delayacct_tsk_init(struct task_struct *tsk) @@ -114,7 +114,7 @@ static inline void delayacct_tsk_free(struct task_struct *tsk) static inline void delayacct_blkio_start(void) { - delayacct_set_flag(DELAYACCT_PF_BLKIO); + delayacct_set_flag(current, DELAYACCT_PF_BLKIO); if (current->delays) __delayacct_blkio_start(); } @@ -123,7 +123,7 @@ static inline void delayacct_blkio_end(struct task_struct *p) { if (p->delays) __delayacct_blkio_end(p); - delayacct_clear_flag(DELAYACCT_PF_BLKIO); + delayacct_clear_flag(p, DELAYACCT_PF_BLKIO); } static inline int delayacct_add_tsk(struct taskstats *d, @@ -166,9 +166,9 @@ static inline void delayacct_thrashing_end(void) } #else -static inline void delayacct_set_flag(int flag) +static inline void delayacct_set_flag(struct task_struct *p, int flag) {} -static inline void delayacct_clear_flag(int flag) +static inline void delayacct_clear_flag(struct task_struct *p, int flag) {} static inline void delayacct_init(void) {} diff --git a/mm/memory.c b/mm/memory.c index 550405fc3b5e..a013d32a6611 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3296,7 +3296,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } - delayacct_set_flag(DELAYACCT_PF_SWAPIN); + delayacct_set_flag(current, DELAYACCT_PF_SWAPIN); page = lookup_swap_cache(entry, vma, vmf->address); swapcache = page; @@ -3347,7 +3347,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vmf->address, &vmf->ptl); if (likely(pte_same(*vmf->pte, vmf->orig_pte))) ret = VM_FAULT_OOM; - delayacct_clear_flag(DELAYACCT_PF_SWAPIN); + delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN); goto unlock; } @@ -3361,13 +3361,13 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) * owner processes (which may be unknown at hwpoison time) */ ret = VM_FAULT_HWPOISON; - delayacct_clear_flag(DELAYACCT_PF_SWAPIN); + delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN); goto out_release; } locked = lock_page_or_retry(page, vma->vm_mm, vmf->flags); - delayacct_clear_flag(DELAYACCT_PF_SWAPIN); + delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN); if (!locked) { ret |= VM_FAULT_RETRY; goto out_release; -- 2.18.2