[haiku-commits] haiku: hrev54484 - src/system/kernel/vm headers/posix/sys headers/private/kernel src/system/kernel

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 1 Aug 2020 15:23:32 -0400 (EDT)

hrev54484 adds 5 changesets to branch 'master'
old head: 4bfc0072e3fedc0d5773151b5ba88172af7e5693
new head: b3aed2adb58406f60c08d66dc69b45770d76650c
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=b3aed2adb584+%5E4bfc0072e3fe

----------------------------------------------------------------------------

8e74e30784c6: kernel/vm: Add discard_address_range that discards pages.
  
  Pages in the given range are unmapped and freed without getting written
  back anywhere. It can be used whenever a caller does not care about the
  data in the given range anymore and wants to reduce page pressure.
  
  Change-Id: I8bcce68fab278efef710d3714677e1d463504a56
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2843
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

b3bd66961a8c: libroot/kernel: Implement MADV_FREE madvise() extension.
  
  It allows an application to signal that it no longer needs the data in
  the given address range and the underlying pages can be discarded and
  reused elsewhere. This is finer grained than working with full areas
  or mappings at a time and enables unmapping sections of partially used
  mappings without giving up its address space.
  
  Compared with punching holes into a mapping by "mapping over" with
  PROT_NONE and MAP_NORESERVE, this has the obvious advantage of not
  producing a lot of unused extra areas and saves the corresponding
  resources. It is also a lot "lighter" of an operation than cutting
  existing areas.
  
  This introduces madvise() alongside the existing posix_madvise() to
  allow for OS specific extensions. The constants for both functions are
  aliased, the POSIX_MADV_* being a subset of the MADV_* ones without the
  non-POSIX extensions. Internally posix_madvise() simply calls madvise().
  
  MADV_FREE is commonly supported in other OSes with various subtle
  semantic differences as to when pages are actually freed/cleared and how
  or whether the pages are counted against the memory use of a process.
  In the variant implemented here, pages are always immediately discarded
  and memory counting is not altered. This behaviour should be considered
  an implementation detail and may be altered later. The actual unmap and
  discard could for example be delayed until pages are needed elsewhere to
  reduce overhead in case of repeated discarding and remapping.
  
  Note that MADV_FREE doesn't really align with the rest of the madvise()
  API as it works like a command (i.e. discard these pages) and does not
  add an attribute to the pages in the given range (i.e. mark these pages
  for quick access from now on). As such, an MADV_FREE does not need to be
  undone by setting a different advice later on, unlike how the other
  flags work. This discrepancy may be the reason why it is not part of
  POSIX.
  
  Change-Id: Icc093379125a43e465dc4409d8f5ae0f64e107e0
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2844
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

2555f33549e6: Cleanup: Various comment and whitespace fixes.
  
  Change-Id: I37c3e3346813efc595df651421b7e8ff4fbf3339
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2845
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

7d432fc911c8: VMKernelAddressSpace: Let Dump() print all ranges.
  
  This makes the output of the aspace KDL command more useful as it shows
  reserved and free ranges in addition to areas.
  
  Change-Id: Id6353820b7c040fce6bfc3297c1b34adb1c9bb99
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2846
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

b3aed2adb584: VMUserAddressSpace: Don't print unset reserved area name in KDL.
  
  Reserved areas don't have the name field initialized, so explicitly
  print "reserved" instead.
  
  Change-Id: I26bcfcb8facb8b5df11a58074506e96a41943e31
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2847
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                            [ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

16 files changed, 169 insertions(+), 27 deletions(-)
headers/posix/sys/mman.h                         | 19 +++--
headers/private/kernel/arch/x86/arch_kernel.h    |  2 +-
headers/private/kernel/lock.h                    |  5 +-
headers/private/kernel/vm/VMCache.h              |  2 +
headers/private/system/vm_defs.h                 |  2 +-
.../kernel/arch/x86/paging/X86VMTranslationMap.h |  2 +-
src/system/kernel/main.cpp                       |  2 +-
src/system/kernel/vm/VMAnonymousCache.cpp        | 10 ++-
src/system/kernel/vm/VMAnonymousCache.h          |  2 +
src/system/kernel/vm/VMCache.cpp                 | 13 +++
src/system/kernel/vm/VMKernelAddressSpace.cpp    | 34 ++++++--
src/system/kernel/vm/VMUserAddressSpace.cpp      |  5 +-
src/system/kernel/vm/vm.cpp                      | 87 +++++++++++++++++++-
src/system/libroot/posix/sys/mman.cpp            |  9 +-
src/system/libroot/stubbed/libroot_stubs.c       |  1 +
.../libroot/stubbed/libroot_stubs_legacy.c       |  1 +

############################################################################

Commit:      8e74e30784c650255874387077f3c1c9865f2712
URL:         https://git.haiku-os.org/haiku/commit/?id=8e74e30784c6
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri May 29 13:23:49 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Aug  1 19:23:27 2020 UTC

kernel/vm: Add discard_address_range that discards pages.

Pages in the given range are unmapped and freed without getting written
back anywhere. It can be used whenever a caller does not care about the
data in the given range anymore and wants to reduce page pressure.

Change-Id: I8bcce68fab278efef710d3714677e1d463504a56
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2843
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/vm/VMCache.h 
b/headers/private/kernel/vm/VMCache.h
index 0aee4f9210..2db12cf3fe 100644
--- a/headers/private/kernel/vm/VMCache.h
+++ b/headers/private/kernel/vm/VMCache.h
@@ -135,6 +135,8 @@ public:
        virtual status_t                        Adopt(VMCache* source, off_t 
offset, off_t size,
                                                                        off_t 
newOffset);
 
+       virtual status_t                        Discard(off_t offset, off_t 
size);
+
                        status_t                        
FlushAndRemoveAllPages();
 
                        void*                           UserData()      { 
return fUserData; }
diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp 
b/src/system/kernel/vm/VMAnonymousCache.cpp
index b5d421f8a4..5baad4c2d0 100644
--- a/src/system/kernel/vm/VMAnonymousCache.cpp
+++ b/src/system/kernel/vm/VMAnonymousCache.cpp
@@ -554,6 +554,14 @@ VMAnonymousCache::Rebase(off_t newBase, int priority)
 }
 
 
+status_t
+VMAnonymousCache::Discard(off_t offset, off_t size)
+{
+       _FreeSwapPageRange(offset, offset + size);
+       return VMCache::Discard(offset, size);
+}
+
+
 /*!    Moves the swap pages for the given range from the source cache into this
        cache. Both caches must be locked.
 */
diff --git a/src/system/kernel/vm/VMAnonymousCache.h 
b/src/system/kernel/vm/VMAnonymousCache.h
index 774c342e33..d463a9705f 100644
--- a/src/system/kernel/vm/VMAnonymousCache.h
+++ b/src/system/kernel/vm/VMAnonymousCache.h
@@ -44,6 +44,8 @@ public:
        virtual status_t                        Adopt(VMCache* source, off_t 
offset,
                                                                        off_t 
size, off_t newOffset);
 
+       virtual status_t                        Discard(off_t offset, off_t 
size);
+
        virtual status_t                        Commit(off_t size, int 
priority);
        virtual bool                            HasPage(off_t offset);
        virtual bool                            DebugHasPage(off_t offset);
diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp
index d4e53c4926..0ccd527680 100644
--- a/src/system/kernel/vm/VMCache.cpp
+++ b/src/system/kernel/vm/VMCache.cpp
@@ -1254,6 +1254,19 @@ VMCache::Adopt(VMCache* source, off_t offset, off_t 
size, off_t newOffset)
 }
 
 
+/*! Discards pages in the given range. */
+status_t
+VMCache::Discard(off_t offset, off_t size)
+{
+       page_num_t startPage = offset >> PAGE_SHIFT;
+       page_num_t endPage = (offset + size + B_PAGE_SIZE - 1) >> PAGE_SHIFT;
+       while (_FreePageRange(pages.GetIterator(startPage, true, true), 
&endPage))
+               ;
+
+       return B_OK;
+}
+
+
 /*!    You have to call this function with the VMCache lock held. */
 status_t
 VMCache::FlushAndRemoveAllPages()
diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp
index fc76b875d8..5048a69cd5 100644
--- a/src/system/kernel/vm/vm.cpp
+++ b/src/system/kernel/vm/vm.cpp
@@ -865,6 +865,52 @@ unmap_address_range(VMAddressSpace* addressSpace, addr_t 
address, addr_t size,
 }
 
 
+static status_t
+discard_area_range(VMArea* area, addr_t address, addr_t size)
+{
+       addr_t offset;
+       if (!intersect_area(area, address, size, offset))
+               return B_OK;
+
+       // If someone else uses the area's cache or it's not an anonymous 
cache, we
+       // can't discard.
+       VMCache* cache = vm_area_get_locked_cache(area);
+       if (cache->areas != area || area->cache_next != NULL
+               || !cache->consumers.IsEmpty() || cache->type != 
CACHE_TYPE_RAM) {
+               return B_OK;
+       }
+
+       VMCacheChainLocker cacheChainLocker(cache);
+       cacheChainLocker.LockAllSourceCaches();
+
+       unmap_pages(area, address, size);
+
+       // Since VMCache::Discard() can temporarily drop the lock, we must
+       // unlock all lower caches to prevent locking order inversion.
+       cacheChainLocker.Unlock(cache);
+       cache->Discard(cache->virtual_base + offset, size);
+       cache->ReleaseRefAndUnlock();
+
+       return B_OK;
+}
+
+
+static status_t
+discard_address_range(VMAddressSpace* addressSpace, addr_t address, addr_t 
size,
+       bool kernel)
+{
+       for (VMAddressSpace::AreaRangeIterator it
+               = addressSpace->GetAreaRangeIterator(address, size);
+                       VMArea* area = it.Next();) {
+               status_t error = discard_area_range(area, address, size);
+               if (error != B_OK)
+                       return error;
+       }
+
+       return B_OK;
+}
+
+
 /*! You need to hold the lock of the cache and the write lock of the address
        space when calling this function.
        Note, that in case of error your cache will be temporarily unlocked.

############################################################################

Commit:      b3bd66961a8cbdf76428bf78f0e2df783219dd79
URL:         https://git.haiku-os.org/haiku/commit/?id=b3bd66961a8c
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri May 29 13:27:13 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Aug  1 19:23:27 2020 UTC

libroot/kernel: Implement MADV_FREE madvise() extension.

It allows an application to signal that it no longer needs the data in
the given address range and the underlying pages can be discarded and
reused elsewhere. This is finer grained than working with full areas
or mappings at a time and enables unmapping sections of partially used
mappings without giving up its address space.

Compared with punching holes into a mapping by "mapping over" with
PROT_NONE and MAP_NORESERVE, this has the obvious advantage of not
producing a lot of unused extra areas and saves the corresponding
resources. It is also a lot "lighter" of an operation than cutting
existing areas.

This introduces madvise() alongside the existing posix_madvise() to
allow for OS specific extensions. The constants for both functions are
aliased, the POSIX_MADV_* being a subset of the MADV_* ones without the
non-POSIX extensions. Internally posix_madvise() simply calls madvise().

MADV_FREE is commonly supported in other OSes with various subtle
semantic differences as to when pages are actually freed/cleared and how
or whether the pages are counted against the memory use of a process.
In the variant implemented here, pages are always immediately discarded
and memory counting is not altered. This behaviour should be considered
an implementation detail and may be altered later. The actual unmap and
discard could for example be delayed until pages are needed elsewhere to
reduce overhead in case of repeated discarding and remapping.

Note that MADV_FREE doesn't really align with the rest of the madvise()
API as it works like a command (i.e. discard these pages) and does not
add an attribute to the pages in the given range (i.e. mark these pages
for quick access from now on). As such, an MADV_FREE does not need to be
undone by setting a different advice later on, unlike how the other
flags work. This discrepancy may be the reason why it is not part of
POSIX.

Change-Id: Icc093379125a43e465dc4409d8f5ae0f64e107e0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2844
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/headers/posix/sys/mman.h b/headers/posix/sys/mman.h
index 40c49c7b5d..8661ad6c9f 100644
--- a/headers/posix/sys/mman.h
+++ b/headers/posix/sys/mman.h
@@ -33,12 +33,20 @@
 #define MS_SYNC                        0x02
 #define MS_INVALIDATE  0x04
 
+/* madvise() values */
+#define MADV_NORMAL                    1
+#define MADV_SEQUENTIAL                2
+#define MADV_RANDOM                    3
+#define MADV_WILLNEED          4
+#define MADV_DONTNEED          5
+#define MADV_FREE                      6
+
 /* posix_madvise() values */
-#define POSIX_MADV_NORMAL              1
-#define POSIX_MADV_SEQUENTIAL  2
-#define POSIX_MADV_RANDOM              3
-#define POSIX_MADV_WILLNEED            4
-#define POSIX_MADV_DONTNEED            5
+#define POSIX_MADV_NORMAL              MADV_NORMAL
+#define POSIX_MADV_SEQUENTIAL  MADV_SEQUENTIAL
+#define POSIX_MADV_RANDOM              MADV_RANDOM
+#define POSIX_MADV_WILLNEED            MADV_WILLNEED
+#define POSIX_MADV_DONTNEED            MADV_DONTNEED
 
 
 __BEGIN_DECLS
@@ -50,6 +58,7 @@ int           munmap(void* address, size_t length);
 int            mprotect(void* address, size_t length, int protection);
 int            msync(void* address, size_t length, int flags);
 
+int            madvise(void* address, size_t length, int advice);
 int            posix_madvise(void* address, size_t length, int advice);
 
 int            shm_open(const char* name, int openMode, mode_t permissions);
diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp
index 5048a69cd5..cc6aff51fb 100644
--- a/src/system/kernel/vm/vm.cpp
+++ b/src/system/kernel/vm/vm.cpp
@@ -6782,9 +6782,46 @@ _user_sync_memory(void* _address, size_t size, uint32 
flags)
 
 
 status_t
-_user_memory_advice(void* address, size_t size, uint32 advice)
+_user_memory_advice(void* _address, size_t size, uint32 advice)
 {
-       // TODO: Implement!
+       addr_t address = (addr_t)_address;
+       if ((address % B_PAGE_SIZE) != 0)
+               return B_BAD_VALUE;
+
+       size = PAGE_ALIGN(size);
+       if (address + size < address || !IS_USER_ADDRESS(address)
+               || !IS_USER_ADDRESS(address + size)) {
+               // weird error code required by POSIX
+               return B_NO_MEMORY;
+       }
+
+       switch (advice) {
+               case MADV_NORMAL:
+               case MADV_SEQUENTIAL:
+               case MADV_RANDOM:
+               case MADV_WILLNEED:
+               case MADV_DONTNEED:
+                       // TODO: Implement!
+                       break;
+
+               case MADV_FREE:
+               {
+                       AddressSpaceWriteLocker locker;
+                       do {
+                               status_t status = 
locker.SetTo(team_get_current_team_id());
+                               if (status != B_OK)
+                                       return status;
+                       } while 
(wait_if_address_range_is_wired(locker.AddressSpace(),
+                                       address, size, &locker));
+
+                       discard_address_range(locker.AddressSpace(), address, 
size, false);
+                       break;
+               }
+
+               default:
+                       return B_BAD_VALUE;
+       }
+
        return B_OK;
 }
 
diff --git a/src/system/libroot/posix/sys/mman.cpp 
b/src/system/libroot/posix/sys/mman.cpp
index 3944538ef9..bb00ab00ef 100644
--- a/src/system/libroot/posix/sys/mman.cpp
+++ b/src/system/libroot/posix/sys/mman.cpp
@@ -181,12 +181,19 @@ msync(void* address, size_t length, int flags)
 
 
 int
-posix_madvise(void* address, size_t length, int advice)
+madvise(void* address, size_t length, int advice)
 {
        RETURN_AND_SET_ERRNO(_kern_memory_advice(address, length, advice));
 }
 
 
+int
+posix_madvise(void* address, size_t length, int advice)
+{
+       return madvise(address, length, advice);
+}
+
+
 int
 shm_open(const char* name, int openMode, mode_t permissions)
 {
diff --git a/src/system/libroot/stubbed/libroot_stubs.c 
b/src/system/libroot/stubbed/libroot_stubs.c
index f65dfa9e00..73d0c7dfd2 100644
--- a/src/system/libroot/stubbed/libroot_stubs.c
+++ b/src/system/libroot/stubbed/libroot_stubs.c
@@ -2336,6 +2336,7 @@ void lroundf() {}
 void lroundl() {}
 void lsearch() {}
 void lseek() {}
+void madvise() {}
 void malloc() {}
 void malloc_usable_size() {}
 void matherr() {}
diff --git a/src/system/libroot/stubbed/libroot_stubs_legacy.c 
b/src/system/libroot/stubbed/libroot_stubs_legacy.c
index fc050f3d18..2de2f3aa35 100644
--- a/src/system/libroot/stubbed/libroot_stubs_legacy.c
+++ b/src/system/libroot/stubbed/libroot_stubs_legacy.c
@@ -2257,6 +2257,7 @@ void lroundf() {}
 void lroundl() {}
 void lsearch() {}
 void lseek() {}
+void madvise() {}
 void makeSuperblock__Q28BPrivate10superblockiPQ28BPrivate11processHeap() {}
 void malloc() {}
 void malloc__Q28BPrivate10threadHeapUl() {}

############################################################################

Commit:      2555f33549e686edc7236b484de5c2b7a3c065d5
URL:         https://git.haiku-os.org/haiku/commit/?id=2555f33549e6
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Thu May 14 19:14:11 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Aug  1 19:23:27 2020 UTC

Cleanup: Various comment and whitespace fixes.

Change-Id: I37c3e3346813efc595df651421b7e8ff4fbf3339
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2845
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/arch/x86/arch_kernel.h 
b/headers/private/kernel/arch/x86/arch_kernel.h
index efd914f6d6..e90175a685 100644
--- a/headers/private/kernel/arch/x86/arch_kernel.h
+++ b/headers/private/kernel/arch/x86/arch_kernel.h
@@ -34,7 +34,7 @@
 // whole kernel address space is the top 512GB of the address space.
 #define KERNEL_BASE                            0xffffff0000000000
 #define KERNEL_SIZE                            0x10000000000
-#define KERNEL_TOP                     (KERNEL_BASE + (KERNEL_SIZE - 1))
+#define KERNEL_TOP                             (KERNEL_BASE + (KERNEL_SIZE - 
1))
 #define KERNEL_LOAD_BASE               0xffffffff80000000
 
 // Kernel physical memory map area.
diff --git a/headers/private/kernel/lock.h b/headers/private/kernel/lock.h
index 92d0dda24a..256b2e66fc 100644
--- a/headers/private/kernel/lock.h
+++ b/headers/private/kernel/lock.h
@@ -154,12 +154,11 @@ extern void mutex_destroy(mutex* lock);
 extern void mutex_transfer_lock(mutex* lock, thread_id thread);
 extern status_t mutex_switch_lock(mutex* from, mutex* to);
        // Unlocks "from" and locks "to" such that unlocking and starting to 
wait
-       // for the lock is atomically. I.e. if "from" guards the object "to" 
belongs
+       // for the lock is atomic. I.e. if "from" guards the object "to" belongs
        // to, the operation is safe as long as "from" is held while destroying
        // "to".
 extern status_t mutex_switch_from_read_lock(rw_lock* from, mutex* to);
-       // Like mutex_switch_lock(), just for a switching from a read-locked
-       // rw_lock.
+       // Like mutex_switch_lock(), just for switching from a read-locked 
rw_lock.
 
 
 // implementation private:
diff --git a/headers/private/system/vm_defs.h b/headers/private/system/vm_defs.h
index eefa895e60..a8988545f8 100644
--- a/headers/private/system/vm_defs.h
+++ b/headers/private/system/vm_defs.h
@@ -17,7 +17,7 @@
        (B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_KERNEL_EXECUTE_AREA \
        | B_KERNEL_STACK_AREA)
 
-// TODO: These aren't really a protection flags, but since the "protection"
+// TODO: These aren't really protection flags, but since the "protection"
 //     field is the only flag field, we currently use it for this.
 //     A cleaner approach would be appreciated - maybe just an official generic
 //     flags region in the protection field.
diff --git a/src/system/kernel/arch/x86/paging/X86VMTranslationMap.h 
b/src/system/kernel/arch/x86/paging/X86VMTranslationMap.h
index a07b314b69..bf632151b5 100644
--- a/src/system/kernel/arch/x86/paging/X86VMTranslationMap.h
+++ b/src/system/kernel/arch/x86/paging/X86VMTranslationMap.h
@@ -27,7 +27,7 @@ struct X86VMTranslationMap : VMTranslationMap {
 
                        status_t                        Init(bool kernel);
 
-       virtual bool                            Lock() final;
+       virtual bool                            Lock() final;
        virtual void                            Unlock() final;
 
        virtual addr_t                          MappedSize() const final;
diff --git a/src/system/kernel/main.cpp b/src/system/kernel/main.cpp
index 2071f6757f..813f508b96 100644
--- a/src/system/kernel/main.cpp
+++ b/src/system/kernel/main.cpp
@@ -8,7 +8,7 @@
  */
 
 
-/*! This is main - initializes the kernel and launches the Bootscript */
+/*! This is main - initializes the kernel and launches the launch_daemon */
 
 
 #include <string.h>
diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp 
b/src/system/kernel/vm/VMAnonymousCache.cpp
index 5baad4c2d0..c043ed4923 100644
--- a/src/system/kernel/vm/VMAnonymousCache.cpp
+++ b/src/system/kernel/vm/VMAnonymousCache.cpp
@@ -958,7 +958,7 @@ VMAnonymousCache::Merge(VMCache* _source)
 {
        VMAnonymousCache* source = dynamic_cast<VMAnonymousCache*>(_source);
        if (source == NULL) {
-               panic("VMAnonymousCache::MergeStore(): merge with incompatible 
cache "
+               panic("VMAnonymousCache::Merge(): merge with incompatible cache 
"
                        "%p requested", _source);
                return;
        }
diff --git a/src/system/kernel/vm/VMUserAddressSpace.cpp 
b/src/system/kernel/vm/VMUserAddressSpace.cpp
index 4e302bc387..d0cf3446f5 100644
--- a/src/system/kernel/vm/VMUserAddressSpace.cpp
+++ b/src/system/kernel/vm/VMUserAddressSpace.cpp
@@ -347,7 +347,7 @@ VMUserAddressSpace::UnreserveAddressRange(addr_t address, 
size_t size,
        // check to see if this address space has entered DELETE state
        if (fDeleting) {
                // okay, someone is trying to delete this address space now, so 
we can't
-               // insert the area, so back out
+               // remove the area, so back out
                return B_BAD_TEAM_ID;
        }
 

############################################################################

Commit:      7d432fc911c8d9f747a643ca32f5417606ad6cb3
URL:         https://git.haiku-os.org/haiku/commit/?id=7d432fc911c8
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri May 29 15:18:40 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Aug  1 19:23:27 2020 UTC

VMKernelAddressSpace: Let Dump() print all ranges.

This makes the output of the aspace KDL command more useful as it shows
reserved and free ranges in addition to areas.

Change-Id: Id6353820b7c040fce6bfc3297c1b34adb1c9bb99
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2846
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/kernel/vm/VMKernelAddressSpace.cpp 
b/src/system/kernel/vm/VMKernelAddressSpace.cpp
index 5db4eb055a..f60364bf85 100644
--- a/src/system/kernel/vm/VMKernelAddressSpace.cpp
+++ b/src/system/kernel/vm/VMKernelAddressSpace.cpp
@@ -482,19 +482,35 @@ VMKernelAddressSpace::Dump() const
 {
        VMAddressSpace::Dump();
 
-       kprintf("area_list:\n");
+       kprintf("range list:\n");
 
        for (RangeList::ConstIterator it = fRangeList.GetIterator();
                        Range* range = it.Next();) {
-               if (range->type != Range::RANGE_AREA)
-                       continue;
 
-               VMKernelArea* area = range->area;
-               kprintf(" area %" B_PRId32 ": ", area->id);
-               kprintf("base_addr = %#" B_PRIxADDR " ", area->Base());
-               kprintf("size = %#" B_PRIxSIZE " ", area->Size());
-               kprintf("name = '%s' ", area->name);
-               kprintf("protection = %#" B_PRIx32 "\n", area->protection);
+               switch (range->type) {
+                       case Range::RANGE_AREA:
+                       {
+                               VMKernelArea* area = range->area;
+                               kprintf(" area %" B_PRId32 ": ", area->id);
+                               kprintf("base_addr = %#" B_PRIxADDR " ", 
area->Base());
+                               kprintf("size = %#" B_PRIxSIZE " ", 
area->Size());
+                               kprintf("name = '%s' ", area->name);
+                               kprintf("protection = %#" B_PRIx32 "\n", 
area->protection);
+                               break;
+                       }
+
+                       case Range::RANGE_RESERVED:
+                               kprintf(" reserved: base_addr = %#" B_PRIxADDR
+                                       " reserved_base = %#" B_PRIxADDR " size 
= %#"
+                                       B_PRIxSIZE " flags = %#" B_PRIx32 "\n", 
range->base,
+                                       range->reserved.base, range->size, 
range->reserved.flags);
+                               break;
+
+                       case Range::RANGE_FREE:
+                               kprintf(" free: base_addr = %#" B_PRIxADDR " 
size = %#"
+                                       B_PRIxSIZE "\n", range->base, 
range->size);
+                               break;
+               }
        }
 }
 

############################################################################

Revision:    hrev54484
Commit:      b3aed2adb58406f60c08d66dc69b45770d76650c
URL:         https://git.haiku-os.org/haiku/commit/?id=b3aed2adb584
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri May 29 15:20:02 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Aug  1 19:23:27 2020 UTC

VMUserAddressSpace: Don't print unset reserved area name in KDL.

Reserved areas don't have the name field initialized, so explicitly
print "reserved" instead.

Change-Id: I26bcfcb8facb8b5df11a58074506e96a41943e31
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2847
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/kernel/vm/VMUserAddressSpace.cpp 
b/src/system/kernel/vm/VMUserAddressSpace.cpp
index d0cf3446f5..23cac2d374 100644
--- a/src/system/kernel/vm/VMUserAddressSpace.cpp
+++ b/src/system/kernel/vm/VMUserAddressSpace.cpp
@@ -400,7 +400,8 @@ VMUserAddressSpace::Dump() const
                kprintf(" area 0x%" B_PRIx32 ": ", area->id);
                kprintf("base_addr = 0x%lx ", area->Base());
                kprintf("size = 0x%lx ", area->Size());
-               kprintf("name = '%s' ", area->name);
+               kprintf("name = '%s' ",
+                       area->id != RESERVED_AREA_ID ? area->name : "reserved");
                kprintf("protection = 0x%" B_PRIx32 "\n", area->protection);
        }
 }


Other related posts:

  • » [haiku-commits] haiku: hrev54484 - src/system/kernel/vm headers/posix/sys headers/private/kernel src/system/kernel - waddlesplash