Message ID | 20230712143831.120701-4-wangkefeng.wang@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1191088vqm; Wed, 12 Jul 2023 07:30:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlFHu69pzgza27vG51u8HiB9CZYCiGyMgGHZh5QfO6k7wj9mX/BIdQKptFNFfjmoc8bNinGL X-Received: by 2002:a17:906:20d7:b0:993:ec0b:1a21 with SMTP id c23-20020a17090620d700b00993ec0b1a21mr14076083ejc.27.1689172218540; Wed, 12 Jul 2023 07:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689172218; cv=none; d=google.com; s=arc-20160816; b=CvUF5DouW/NzbBiSasRB/DXnXZVPVhXbj7wCrsXtGKM+t7cxPgHH6KAgdZFhcefsiX FeG0mgWGDgMYUHgD7NEHl9FLNU2Xn5xU7RNGdqsZ9AFuKxoOVnSQbcIJV/MlTOGuCtMk Sb/3KTH0R1hWgoZByKx5pgmbGE83Du4X6qCtvLCOHENUInlKRWkeF2SLiqciwvwet5pY 7zLjCb5pULG7/JkE4JxgBRdUKrmcKXWWOT5941dtBAxMEwfr7Nt/Ufew1Cy2qGXiL2e1 ckpmI4q9/ylE1LFIqM1lFt4Ly6u3qYrTSpbunER5AL3uztxNlufJRj9zbqduzyg1sJKn e2pg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ETNPB7wUh0SNwnx9DDYb/PlWZoZqHTNfB+0DsPV8JQI=; fh=FRon72YwFeIVU/LlfmPNxuVFiduvQKfa+Ydvnh8xLfc=; b=qnP0IK0NqCwUsOUCWLnBWuFoibAywwlQb2yxwn6at6tuesEKYjAC1w7CKKYlDhF7L1 hDmIU8nN1eNfQokFAf20OiwqN26WwBAax9uksryZyZ27IvSyCLXb0aQ1hrp1YMwoIIwS ftBsQ9dqmolLus9gyjBTV3drE1WASgJSsmeOEO2SFr7L9+pG+8ZqL0YPAubRIYdPu4jf eolntYaww4hUKosyzCA67ZzdPKuh5OXvhCyemS/0/Yg45JeqY3JaQv1jUDTJsQwXNzgp /0xAJj+gLFctYkECa/V4lpRie1nP9PP/+ynYdzUzZOscAkSTg465l/rRn4UFOpKSD74v Em5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd1-20020a170906ce2100b00988a83822d8si4781865ejb.938.2023.07.12.07.29.53; Wed, 12 Jul 2023 07:30:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232606AbjGLOZe (ORCPT <rfc822;gnulinuxfreebsd@gmail.com> + 99 others); Wed, 12 Jul 2023 10:25:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232441AbjGLOZW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 12 Jul 2023 10:25:22 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D491BC6; Wed, 12 Jul 2023 07:25:17 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R1Kkb0rdCz1JCP8; Wed, 12 Jul 2023 22:24:39 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 12 Jul 2023 22:25:13 +0800 From: Kefeng Wang <wangkefeng.wang@huawei.com> To: Andrew Morton <akpm@linux-foundation.org> CC: <amd-gfx@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>, <linux-mm@kvack.org>, <linux-perf-users@vger.kernel.org>, <selinux@vger.kernel.org>, Kefeng Wang <wangkefeng.wang@huawei.com> Subject: [PATCH 3/5] drm/amdkfd: use vma_is_stack() and vma_is_heap() Date: Wed, 12 Jul 2023 22:38:29 +0800 Message-ID: <20230712143831.120701-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712143831.120701-1-wangkefeng.wang@huawei.com> References: <20230712143831.120701-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771225448275128502 X-GMAIL-MSGID: 1771225448275128502 |
Series |
mm: convert to vma_is_heap/stack()
|
|
Commit Message
Kefeng Wang
July 12, 2023, 2:38 p.m. UTC
Use the helpers to simplify code.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Comments
On Wed, Jul 12, 2023 at 10:38:29PM +0800, Kefeng Wang wrote:
> Use the helpers to simplify code.
Nothing against your addition of a helper, but a GPU driver really
should have no business even looking at this information..
Allocations in the heap and stack tend to be small, with several allocations sharing the same page. Sharing the same page for different allocations with different access patterns leads to thrashing when we migrate data back and forth on GPU and CPU access. To avoid this we disable HMM migrations for head and stack VMAs. Regards, Felix Am 2023-07-12 um 10:42 schrieb Christoph Hellwig: > On Wed, Jul 12, 2023 at 10:38:29PM +0800, Kefeng Wang wrote: >> Use the helpers to simplify code. > Nothing against your addition of a helper, but a GPU driver really > should have no business even looking at this information.. > >
On 7/12/23 18:24, Felix Kuehling wrote: > Allocations in the heap and stack tend to be small, with several > allocations sharing the same page. Sharing the same page for different > allocations with different access patterns leads to thrashing when we > migrate data back and forth on GPU and CPU access. To avoid this we > disable HMM migrations for head and stack VMAs. Wonder how well does it really work in practice? AFAIK "heaps" (malloc()) today uses various arenas obtained by mmap() and not a single brk() managed space anymore? And programs might be multithreaded, thus have multiple stacks, while vma_is_stack() will recognize only the initial one... Vlastimil > Regards, > Felix > > > Am 2023-07-12 um 10:42 schrieb Christoph Hellwig: >> On Wed, Jul 12, 2023 at 10:38:29PM +0800, Kefeng Wang wrote: >>> Use the helpers to simplify code. >> Nothing against your addition of a helper, but a GPU driver really >> should have no business even looking at this information.. >> >> >
Am 2023-07-14 um 10:26 schrieb Vlastimil Babka: > On 7/12/23 18:24, Felix Kuehling wrote: >> Allocations in the heap and stack tend to be small, with several >> allocations sharing the same page. Sharing the same page for different >> allocations with different access patterns leads to thrashing when we >> migrate data back and forth on GPU and CPU access. To avoid this we >> disable HMM migrations for head and stack VMAs. > Wonder how well does it really work in practice? AFAIK "heaps" (malloc()) > today uses various arenas obtained by mmap() and not a single brk() managed > space anymore? And programs might be multithreaded, thus have multiple > stacks, while vma_is_stack() will recognize only the initial one... Thanks for these pointers. I have not heard of such problems with mmap arenas and multiple thread stacks in practice. But I'll keep it in mind in case we observe unexpected thrashing in the future. FWIW, we once had the opposite problem of a custom malloc implementation that used sbrk for very large allocations. This disabled migrations of large buffers unexpectedly. I agree that eventually we'll want a more dynamic way of detecting and suppressing thrashing that's based on observed memory access patterns. Getting this right is probably trickier than it sounds, so I'd prefer to have some more experience with real workloads to use as benchmarks. Compared to other things we're working on, this is fairly low on our priority list at the moment. Using the VMA flags is a simple and effective method for now, at least until we see it failing in real workloads. Regards, Felix > > Vlastimil > >> Regards, >> Felix >> >> >> Am 2023-07-12 um 10:42 schrieb Christoph Hellwig: >>> On Wed, Jul 12, 2023 at 10:38:29PM +0800, Kefeng Wang wrote: >>>> Use the helpers to simplify code. >>> Nothing against your addition of a helper, but a GPU driver really >>> should have no business even looking at this information.. >>> >>>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c index 479c4f66afa7..19ce68a7e1a8 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -2623,10 +2623,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr, return -EFAULT; } - *is_heap_stack = (vma->vm_start <= vma->vm_mm->brk && - vma->vm_end >= vma->vm_mm->start_brk) || - (vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack); + *is_heap_stack = vma_is_heap(vma) || vma_is_stack(vma); start_limit = max(vma->vm_start >> PAGE_SHIFT, (unsigned long)ALIGN_DOWN(addr, 2UL << 8));