Building Dynamic Memory Allocators

麒麟/linux桌面客户端终端SSH远程服务器及scp、sftp 上传文件步骤 在麒麟/Linux系统上,无需安装额外软件,可直接使用内置的ssh、scp、sftp等命令实现远程登录、指令执行及文件上传下载。通过终端输入ssh root@10.10.xx.xxx登录服务器,首次连接确认指纹后输入密码(盲打),即可操作。文件传输使用scp单文件/目录上传,或sftp交互式传输;也可在文件管理器中输入sftp://root@10.10.xx.xxx实现图形化拖拽。支持免密登录配置与断点续传的rsync,全面替代MobaXterm功能,高效安全。 阅读详情
Outline
Due date: 13 September 2024, 23:59
Mark weighting: 20%
Submission: Submit your assignment through GitLab (full instructions below)
Policies: For late policies, plagiarism policies, etc., see the policies page
Time left
5 :03:12:58
Days
Hrs
Mins Secs
warn
This assignment builds upon the following labs:
Lab 5: Building Dynamic Memory Allocators
Lab 6: Sanity Checking Implicit Free List Implementation
If you have not completed the tasks in the above labs or do not understand the content,
we strongly recommend that you first complete the labs and then start the assignment.
Introduction
Managing memory is a major part of programming in C. You have used malloc() and
free() in the recent labs. You have also built a very basic memory allocator, and it is
now time to build a more advanced allocator. In this assignment, you will implement a
memory allocator, which allows users to malloc() and free() memory as needed. Your
allocator will request large chunks of memory from the OS and efficiently manage all
the bookkeeping and memory. The allocator we ask you to implement is inspired by the
DLMalloc allocator designed by Doug Lea. The DLMalloc allocator also inspired the
PTMalloc allocator, which GLibC currently uses. Indeed, our allocator is a simplified
version of DLMalloc, but you will also notice many similarities.
Background
We hope that the last two labs have motivated the need for dynamic memory allocators.
Specifically, we have seen that while it is certainly possible to use the low-level mmap
and munmap functions to manage areas of virtual memory, programmers need theconvenience and efficiency of more fine-grained memory allocators. If we managed the
memory from the OS ourselves, we could allow allocating and freeing variables in any
order, and also reuse memory for other variables.
The last lab taught you how best to build an implicit free list allocator for managing free
blocks. In this assignment, we will first build a more efficient free list data structure
called an explicit free list. We will also change our placement policy to best fit, and then
perform a number of optimizations.
Explicit free list
The block allocation time with an implicit free list is linear in the total number of heap
blocks which is not suitable for a high-performance allocator. We can add a next and
previous pointer to each block’s metadata so that we can iterate over the unallocated
blocks. The resulting linked list data structure is called an explicit free list. Using a
doubly linked list instead of a free list reduces the allocation time from linear in the total
number of blocks to linear in the total number of free blocks.
Dealing with memory fragmentation
Fragmentation occurs when otherwise unused memory is not available to satisfy
allocate requests. This phenomenon happens because when we split up large blocks into
smaller ones to fulfill user requests for memory, we end up with many small blocks.
However, some of those blocks may be able to be merged back into a larger block. To
address this issue requires us to iterate over the free list and make an effort to find if the
block we are trying to free is adjacent to another already free block. If neighboring
blocks are free, we can coalesce them into a single larger block.
Placement policy
Memory fragmentation is also affected by placement policy, which is how you choose a
block to allocate when given a choice between multiple free blocks which are suitable
(large enough). The policy we used in Lab 5 was the first fit policy, returning the first
free block we find. There are a number of alternative strategies with the aim of targeting
fragmentation, sometimes with a tradeoff of performance:
Best fit, returning the smallest suitable free block (leaves bigger free blocks
available).
Next fit, which starts looking for a free block from where the previous allocation
was (addresses issues with First Fit such as a tendency to allocate memory at the
beginning of the chunk and create more fragments there)The base spec of this assignment requires you to implement best fit. Note that in the
most naive explicit free list implementation, this does come at the performance cost of
looking through the entire free list! But one of the optimisations we describe below will
heavily mitigate this. You may also consider your own ideas for mitigating this cost.
Dealing with the edges of chunks
One detail we must consider is how to handle the edges of the chunks from the OS. If we
simply start the first allocable block at the beginning of the memory chunk, then we may
run into problems when trying to free the block later. This is because a block at the edge
of the chunk is missing a neighbor. A simple solution to this is to insert a pair of
fenceposts at either end of the chunk. The fencepost is a dummy header containing no
allocable memory, but which serves as a neighbor to the first and last allocable blocks in
the chunk. Now we can look up the neighbors of those blocks and don’t have to worry
about accidentally coalescing outside of the memory chunk allocated by the OS,
because anytime one of the neighbors is a fencepost we cannot coalesce in that
direction.
Optimizations (CR-D level)
We will also perform the following optimizations as part of the assignment to improve
the space and time complexity of our memory allocator.
Reducing the Metadata Footprint
Naive solution: In our description of the explicit free list above, we assume the
memory allocated to the user begins after all of the block’s metadata. We must
maintain the metadata like size and allocation status because we need it in the
block’s header when we free the object.
Optimization 1: While we need to maintain the size and allocation status, we only
use the free list pointers when the object is free. If the object has been allocated, it
is no longer in a free list; thus, the memory used to store the pointers can be used
for other purposes. By placing the next and previous pointers at the end of the
metadata, we can save an additional 2 * sizeof(pointer) bytes and add that to the
memory allocated to the user.
Optimization 2: The allocated flag that tells if a block is allocated or not uses only
one bit. Since the sizes are rounded up to the next 8 bytes, the last three bits are
not used. Instead of using a boolean to store the allocated flag, we can use one of
the unused bits in size. That will save an additional 8 bytes.Constant Time Coalesce
Naive solution: We mentioned above that we could iterate over the free list to find
blocks that are next to each other, but unfortunately, that makes the free operation
O(n), where n is the number of blocks in the list.
Optimized solution: The solution we will use is to add another data structure called
Boundary Tags, which allows us to calculate the location of the right and left
blocks in memory. To calculate the location of the block to the right, all we need to
know is the size of the current block. To calculate the location of the block to the
left, we must also maintain the size of the block to the left in each block’s
metadata. Now we can find the neighboring blocks in O(1) time instead of O(n).
Multiple Free Lists
Naive solution: So far, we have assumed a single free list containing all free blocks.
To find a block large enough to satisfy a request, we must iterate over all the
blocks to find a block large enough to fulfil the request. For best fit, we also need
to look through ALL of the free blocks to find the best such block.
Optimized solution: We can use multiple free lists. We create n free lists1 , one for
each allocation size (8, 16, …, 8*(n-1), 8*n bytes.) That way, when a user requests
memory, we can jump directly to the list representing blocks that are the correct
size instead of looking through a general list. If that list is empty, the next non
empty list will contain the block best fitting the allocation request. However, we
only have n lists, so if the user requests 8*n bytes of memory or more, we fall
back to the naive approach and scan the final list for blocks that can satisfy the
request. This optimization cannot guarantee an O(1) allocation time for all
allocations. Still, for any allocation under 8*n, the allocation time is O(number of
free lists) as opposed to O(length of the free list).
Getting Additional Chunks From the OS
The allocator may be unable to find a fit for the requested block. If the free blocks are
already maximally coalesced, then the allocator asks the kernel for additional heap
memory by calling mmap . The allocator transforms the additional memory into one large
free block, inserts the block in the free list, and then places the requested block in this
new free block.
Note that for the purposes of performance analysis and calculating fragmentation (see
below), and for determining invalid pointers passed to free due to them not lying in any
allocated chunk, you will need to implement a way to iterate through all of the chunksand keep track of where they all are. Hint: consider using a linked list and extra fields in
the chunk fenceposts.
Performance Measurement (CR-level)
Given the effort that we are going to in order to optimise the performance of our
allocator, we would like to know that it is actually having an effect! There are two
primary metrics for the performance of the allocator:
Execution time: The raw best/average/worst time it takes to perform an allocation,
and to free.
Fragmentation: Measuring the allocator’s ability to efficiently use memory. Divided
into two classes: internal fragmentation, created by space inside blocks which is
unusable (e.g. extra padding to meet alignment constraints or metadata), and
external fragmentation, caused by space being divided up too much and there
being small “fragments” in between allocated blocks which cannot satisfy most
requests and sit there wasting space.
It is worth noting that these metrics will change based on these inputs:
Number of allocations made so far/how long the program has been running
Allocation and freeing patterns
As you add optimisations and improve your allocator, you should compare your new
iterations’ performance to your old one. This will involve keeping different versions of
your allocator allowed in different files (we will advise how to run tests on the allocator
given in a specific file in the testing section). You are required to at least analyse the
performance benefit arising from your “best” optimisation, e.g. multiple free lists, by
comparing a version of the allocator with and without it. You will be asked to analyse this
in your report.
Note that if you don’t keep any prior versions, this is also fine, you will just have to make
a baseline allocator to compare against (by copying the current allocator to a new file
and undoing your best optimisation) yourself.
Measuring execution time and fragmentation
Measuring execution time is straightforward using the Linux time command on a
program which is making some number of allocations.
Measuring fragmentation is more tricky. The lectures describe a metric called peak
memory utilisation which you can use for this; see Slides 12-14 in the “malloc-basic” halfof Week 6’s lectures for details. This will require you to sum up the payload sizes across
all blocks, which requires iterating through all of the blocks (in each chunk) in the first
place; we will have you define helper functions for doing this. You can also develop your
own metrics for measuring fragmentation if you wish.
We will provide you benchmarking programs on which you can measure these metrics
and see how they scale with number of allocations. See the benchmarking section for
more.
Garbage Collector (HD-level)
A critical pitfall of the malloc / free manual style of memory management is that if
the user forgets to free memory, it results in a memory leak, i.e., memory is consumed
even if the block is no longer used or not even reachable by the program. The garbage
collector (GC) is an alternative to manual freeing that takes this burden off the user by
automatically figuring out if allocations are still being used, and freeing those which are
not (i.e., dead memory). You will implement what is called a “conservative mark-and
sweep GC” in this assignment.
Basic idea
The basic idea is simple. The program has a bunch of variables which it can access
directly by name which we call the roots. The roots consist of local variables as well as
global variables (though for simplicity we will ignore the latter for this assignment).
These roots can then be pointers to objects on the heap, which may themselves be
pointers, and so on. Any object which cannot be reached by a series of pointer
dereferences starting from the roots is unreachable and hence garbage, and can safely
be deallocated. Meanwhile, if an object IS reachable, then it may still be used later in the
program and we cannot free its memory.
Our GC will be a function that frees all blocks that do not contain any reachable objects.
The GC consists of two phases: mark and sweep. In the mark phase, we start from the
roots and look for pointers to locations on the heap. If we find a pointer that points to a
location within a block on the heap, we “mark” that block as reachable by changing a
flag in the header (similar to the allocated flag). Once done, we then go through and free
all of the allocated blocks that were not marked in the “sweep” phase.
The mark flag can be implemented as one of the unused bits at the end of the size
parameter in your header.Modifying malloc
malloc
malloc
and free
free
free
Your malloc and free will need to be modified a bit so that they maintain a data structure
tracking the allocated blocks and the locations of their headers. The reasons are
twofold:
In the mark phase, if you have a pointer to the middle of a block, you will need to
then find the header of the block in order to set the mark flag. This can be done by
going through all the allocated block headers and choosing the one corresponding
to the block containing the pointer’s location.
In the sweep phase, you need to go through each of the allocated blocks when
freeing the unmarked ones.
One way is to keep next/prev pointers in the headers of allocated blocks and having your
malloc/free maintain a “used list”, similar to the free lists you’ve used so far. Of course,
this uses extra metadata, and you need to go through all of the allocated blocks just to
find the header of a single one. You are encouraged to use a better approach if you can
think of one.
Conservative GC
Now, the idea of an “object” in C is quite loose, and there are two problems:
Any value can be cast to a pointer and dereferenced. So even if a variable is of type
int , it has to be treated as a pointer.
A pointer points to a single location in memory, but using pointer offsets we could
also access nearby locations. E.g. if the pointer points to an array we’d access the
elements of that array via offsets. Given a pointer, you can’t tell where the object
pointed to begins and ends.
This is why we will make our allocator “conservative”, which means that it may fail to free
some blocks which are actually garbage, but it will never free a block which may be
used. In practice:
When checking the local variables/roots for pointers we scan the entire stack,
casting all word-aligned values to pointers (as any of them may be interpreted as
pointers).
When a pointer to a block is found, we don’t just check the value being pointed to
but all other word-aligned values in that block for further pointers (as those values
can be accessed by offsets from the original pointer).info
In order to have a more “precise” GC, you need more support from the
programming language and the compiler to provide constraints on what objects
can be and how you define them, which allows things like having metadata inside
the objects themselves so that we can mark individual objects rather than blocks.
GCs in practice tend to be built into the programming language itself, such as in
Java. You may learn more about this if you take a compiler course in future.
Lab Specification
Malloc spec
You can read the malloc interface on the malloc man page. Many details are left up to
the library’s authors. For instance, consider the many optimizations we mention above.
All versions of malloc would be correct by the specification on the man page, but some
are more efficient than others.
We will also require you to define a set of malloc helper functions. The reasons for these
are two-fold:
The helper functions can be used to implement “internal” tests that allow writing
unit tests for sub-parts of the malloc. The helper functions also allow probing the
“free space” currently available to malloc and assessing fragmentation without
knowing the internal implementation details. This will be used in both tests and
benchmarking.
Splitting up code into helper functions is good style, and you will find many of
these helper functions useful for modularising your code.
Our Implementation Spec
The major elements of the base spec of our malloc are as follows:
Use an explicit free list
Use the best fit placement policy
We will also implement special behavior for my_free to do no-op in cases where the
pointer being freed is obviously invalid, i.e. does not correspond to a malloc call. We don’t
require handling all such cases, e.g. pointers into the middle of blocks, but the following
cases should be handled gracefully:free is called when the memory allocator has not been initialised
free is called with a pointer which is not in the range of any of the chunks
mmapped by the allocator
We have described the basic implementation we want you to follow with optimizations in
the background and optimization sections above. We now provide the technical
specification of the required design. Some of the requirements are in place to enforce
conformance to the design, and others guarantee determinism between our reference
allocator and your allocator for testing. The specification below should contain all the
details necessary to ensure your implementation is consistent with the reference
implementation.
Data Structures and Constants
We provide certain constants namely:
1. kMemorySize : When requesting a chunk of memory from the OS for allocation,
we always get a multiple of 64MB. For objects larger than 64 MB, you will have to
use a multiple of 64 MB.
2. kAlignment : We require word-aligned addresses from our allocations.
3. kMinAllocationSize : We set the minimum allocation size for our allocator to be
1 word.
4. kMaxAllocationSize : We set the maximum allocation size for our allocator to
be 128 MB - size of your meta-data. Note that this is the maximum allocation size an
individual request to my_malloc . It is possible for the total size across all
allocations to be greater than kMaxAllocationSize .
5. N_LISTS : We set the number of free lists in to be 59 . This is only relevant when
implementing the “Multiple Free Lists” optimisation.
Marking and Grading Criteria
You are required to submit a completed and working implementation of malloc
according to this spec, as well as a report discussing your implementation. The marks
will be split in the following way:
Code (60%)
Report, including performance analysis (40%)
The following description of grading categories assumes you submit both the code for
your malloc implementation and the report.warn
Keep in mind that just attempting the given tasks for a grade band is not enough
to guarantee you receive a final mark in that grade band. Things like correctness
of your implementation, report quality and code style will all influence your
results. This is just provided as a guideline.
P
You will be rewarded a maximum grade of P if you complete the following tasks.
Implement a single explicit free list with best fit placement policy
Linear time coalescing
Fence posts
hint
To be able to fulfil kMaxAllocationSize requests after you have implemented
fence posts, you can either:
Modify the kMaxAllocationSize constant to subtract the size taken up
by the fence posts.
Modify your code to calculate how many multiples of 64MB the call to
mmap should request, so that it takes the size of the fenceposts into
consideration.
CR
You will be rewarded a maximum grade of CR if you complete the following tasks.
All tasks in the P category
Metadata reduction
Constant time coalescing with boundary tags
Requesting additional chunks from the OS
Performance analysis on the effect of the extensions in this category
DYou will be rewarded a maximum grade of D if you complete the following tasks.
All tasks in the P and CR categories
Multiple free lists
Performance analysis on the effect of the extensions in this category
HD
You will be rewarded a maximum grade of HD if you complete the following tasks.
All tasks in the P , CR and D categories
The garbage collector
Detailed specification
Here, we elaborate further on the exact specification for each task.
Allocation
An allocation of 0 bytes should return the NULL pointer for determinism.
All chunks requested from the OS should be a multiple of size kMemorySize
defined in mymalloc.h.
All requests from the user are rounded up to the nearest multiple of kAlignment
(8 bytes).
The minimum request size is the size of the full header struct. Even though the
pointer fields at the end of the header are not used when the block is allocated,
they are necessary when the block is free, and if space is not reserved for them, it
could lead to memory corruption when freeing the block.
When allocating from the final free list ( N_LISTS - 1 ), the blocks are allocated
in best-fit order: you will iterate the list and look for the smallest block large
enough to satisfy the request size. Given that all other lists are multiples of 8, and
all blocks in each list are the same size, this is not an issue with the other lists.
When allocating a block, there are a few cases to consider:
If the block is exactly the request size, the block is simply removed from the
free list.
If the block is larger than the request size, but the remainder is too small to
be allocated on its own, the extra memory is included in the memory
allocated to the user and the full block is still allocated just as if it had been
exactly the right size.
If the block is larger than the request size and the remainder is large enough
to be allocated on its own, the block is split into two smaller blocks. We couldallocate either of the blocks to the user, but for determinism, the user is
allocated the block which is higher in memory (the rightmost block).
When splitting a block, if the size of the remaining block is no longer
appropriate for the current list, the remainder block should be removed and
inserted into the appropriate free list.
When no available block can satisfy the user’s request, we must request another
chunk of memory from the OS and retry the allocation. On initialization of the
library, the allocator obtains a chunk from the OS and inserts it into the free list.
The pointer to the new chunk should be saved somewhere in a way that allows
traversing across all of the chunks in some order.
In operating systems, you can never expect a call to the OS to work all the time. If
allocating a new chunk from the OS fails, your code should return the NULL
pointer, and errno should be set appropriately (check the man page).
The allocator should allocate new chunks lazily. Specifically, the allocator requests
more memory only when servicing a request that cannot be satisfied by any
available free blocks.
Deallocation
Freeing a NULL pointer is a no-op (don’t do anything).
When freeing a block, you need to consider a few cases:
Neither the right nor the left blocks are unallocated. In this case, simply insert
the block into the appropriate free list
Only the right block is unallocated. Then coalesce the current and right
blocks together. The newly coalesced block should remain where the right
block was in the free list
Only the left block is unallocated. Then coalesce the current and left blocks,
and the newly coalesced block should remain where the left block was in the
free list.
Both the right and left blocks are unallocated, and we must coalesce with
both neighbors. In this case, the coalesced block should remain where the left
block (lower in memory) was in the free list.
When coalescing a block, if the size of the coalesced block is no longer appropriate
for the current list, the newly formed block should be removed and inserted into
the appropriate free list. (Note: This applies even to cases above where it is
mentioned to leave the block where it was in the free list.)
my_free should behave gracefully (i.e. not crash) when given obviously invalid
memory addresses. For the purposes of this requirement an invalid memory
address is one which is not in the range of any of the chunks mmapped by the
my_malloc .Garbage collection
Garbage collector uses a modified version of malloc that creates a “used list” or
other data structure to track allocated blocks, potentially using extra metadata in
blocks to do so. Your free will also need to remove blocks from this data
structure.
Garbage collection is a function that can be called by the program anytime, like
“free” except you don’t need to tell it what to free (it will figure it out by itself)
GC’s mark phase scans the entire stack and considers any word-aligned value in
the stack as a pointer
You are already provided a function get_end_of_stack() that returns a pointer
to the end of the stack, and there is also a global variable start_of_stack
which you can assume has been pre-initialised to the start of main() ’s stack
frame. The use of these two is demonstrated in the template file for GC that you’re
provided.
GC ignores global variables and variables stored in registers
If a pointer to a block is found, the entire block is scanned for further pointers
GC is resistant to circular references and mark phase does not re-scan a block that
it’s already scanned. E.g. if block 1 contains a pointer to block 2, which contains a
pointer back to block 1, your mark phase must not fall into an infinite loop.
When sweeping/freeing unused blocks, garbage blocks are removed from the used
list (or analogous data structure) and added to the appropriate free lists, and the
same rules for coalescing described for free are applied.
Tasks
Your task is to implement malloc (memory allocator) and include in your
implementation the various requirements and optimizations discussed above. Broadly,
your coding tasks are three-fold.
Allocation
1. Calculate the required block size.
2. Find the appropriate free list to look for a block to allocate.
3. Depending on the size of the block, either allocate the full block or split the block
and allocate the right (higher in memory) portion to the user.
4. When allocating a block, update its allocation status.
5. Finally, return the user a pointer to the data field of the header.Deallocation (Freeing)
1. Free is called on the same pointer that malloc returned, which means we must
calculate the location of the header by pointer arithmetic. Hint: You will most likely
want to use the ptr_to_block helper function for this.
2. Once we have the block’s header freed, we must calculate the locations of its right
and left neighbors, using pointer arithmetic and the block’s size fields.
3. Based on the allocation status of the neighboring blocks, we must either insert the
block or coalesce it with one or both of the neighboring blocks.
Managing additional chunks
Handle the case where the user’s request cannot be fulfilled by any of the available
blocks. Also implement a method for traversing across all of the chunks currently used
by the allocator, for use in calculating fragmentation and detecting invalid frees.
warn
Note that the tests we provide will succeed even if you submit an mmap or an
implicit free list allocator. The success of these provided tests on a non-explicit
free list allocator does not mean you are done. Do not submit code files with
allocators from a previous lab. We have tests to ensure compliance with the
assignment specification.
Garbage Collection
1. Modify malloc and free to maintain additional data structures your GC needs
2. Iterate from the beginning to the end of the stack. For each value in the stack, find
if that value is an address to a location inside an allocated block. If such a block is
found, set its mark flag.
3. Recursively scan each block marked in step 2 for pointers to further blocks until no
more blocks can be marked.
4. Go through all allocated blocks and call free for any remaining unmarked blocks.
Performance analysis
1. Implement at least the peak memory utilisation metric for fragmentation.
2. Measure and compare execution time and fragmentation for various levels of
optimisation of your allocator, and for various input sizes. At least comparing your“best” allocator with some kind of “base” or “second best” is required.
Report
You must submit a report that describes your malloc implementation. It should be written
in the given report.md file as valid markdown and split up into the following sections.
Some of these will be omitted if you did not complete those specific optimisations:
Overview of your memory allocator, and the data structures used. (100-300 words)
You should make it clear what optimisations you have attempted in this
Overview section, but leave the important details until the relevant
optimisation section.
You should include a high level explanation of how your best fit allocation
strategy operates, how coalescing is implemented, and how fenceposts were
implemented.
Optimisations: for each of the following optimisations you attempt, include a
section going into more detail about how you implemented it and what effect (if
any) it had on your memory allocator:
Metadata Reduction (50-100 words)
Constant time coalescing with boundary tags (50-150 words)
Requesting additional chunks from the OS (50-150 words)
Multiple Free Lists (50-200 words)
Garbage Collector Overview: (100-500 words)
If you implemented the garbage collector provide an overview of how your
garbage collector works and the changes you made to the metadata stored.
Describe any problems with implementing a garbage collector in C, and why
garbage collectors in general require more support from the programming
language itself.
Testing: (100-300 words)
You should include at least one of the following:
Explanation of an implementation challenge encountered in completing
this assignment. This could include a difficult bug you faced or a
conceptual problem you got stuck on.
Explanation of additional tests you created to verify your malloc and/or
garbage collector implementation
If there are any known bugs in your implementation, list them here in
this section.
Benchmarking Results: (100-300 words)
Include a summary of your memory allocators performance under the
benchmark script. Identify any optimisations you performed that improvedthe results significantly.
Include any measurements of memory fragmentation you computed.
warn
The report job of the CI will fail if you exceed 1200 words. If your report is still
within the word count indicated above (2000 words), you are allowed to safely
ignore this failure.
Marking
The code is worth 60% of your grade (in your specific category). The report is worth 40%
of the grade.
Note that having appropriate code style will contribute a small amount to your code
mark. This means you should:
Have clear names for functions and variables
Have comments explaining what more complex functions do
Remove any commented out code before submission
Remove excessive whitespace
Have consistent whitespace
Make sure you only use the LOG macro to print things to stdout/stderr, so these
are automatically removed when a release build is used.
Coding and Implementation
Fork the Assignment 1 repo and then clone it locally.
mymalloc.h
This file contains the type signatures of my_malloc and my_free , various required
helper functions and some pre-defined constants. Importantly this will contain the initial
definition of the Block data structure. You are allowed to modify this file as needed,
but it is your responsibility to make sure the changes are compatible with the CI and the
tests.
mymalloc.cThis file will contain your implementation of the my_malloc and my_free functions.
We only provide some constants to help with your implementation. Your task will be to
implement an explicit free-list allocator. We recommend using a modular approach with
judicious use of helper functions as well as explanatory comments. You can insert
logging calls with the LOG() macro we provide.
Helper functions
We provide a number of helper functions in mymalloc.h and mymalloc.c :
int is_free(Block *block) : Return 1 if the given block is free, 0 if not
size_t block_size(Block *block) : Return the size of the given block
Block *get_start_block(void) : Returns the first block in memory (excluding
fenceposts). If there are multiple chunks, return the first block in the first chunk.
Block *get_next_block(Block *block) : Return the next block,
contiguously, in memory. If this is the last block of a chunk, return the first block of
the next chunk. If this is the last chunk, return NULL.
Block *ptr_to_block(void *ptr) : Given a ptr assumed to be returned from
a previous call to my_malloc , return a pointer to the start of the metadata block.
Many of these helper functions will help you in writing various versions of the allocator.
These also provide an interface for accessing and testing the internals of the allocator,
as well as benchmarking. In particular, the get_start_block and get_next_block
helpers will help you calculate fragmentation.
Various optimisations will require you to change your implementation of these helpers:
is_free and block_size will change when you implement metadata reduction.
This will also make these functions non-trivial (and actually useful).
get_start_block and get_next_block are sensitive to adding the multiple
chunks feature. You need to track both a “first” chunk and a way to go from a given
chunk to the “next” chunk.
mygc.h
This file contains type signatures for some additional functions that are described
immediately below.
mygc.c
This file will contain your implementation of my_malloc_gc and my_free_gc , the
modified versions of my_malloc and my_free to add extra elements to facilitate theGC, as well as your implementation of my_gc , the garbage collector. You are
recommended to first copy in your implementations of my_malloc and my_free from
the main C files, as well as any constants and helper functions you had defined there.
We also provide the function get_end_of_stack() and the external variable
start_of_stack (which we will set at the beginning of our test functions to
correspond to the start of stack) to give you the endpoints of the stack for convenience.
mygctest.c
A file with a template main() function where you can insert calls to your GC and test
that it frees garbage, avoids freeing reachable blocks, and so on. You are advised not to
modify the initialisation of the start_of_stack variable in this file and use the
provided my_calloc_gc . Add whatever you want in this file otherwise for testing your
GC.
warn
Note that if you define your tests in seperate functions in this file and call those
functions in main() , then because the GC includes all functions in the call stack
when scanning the stack, it will include any variables you defined in main()
when scanning. So be careful of that.
test.py
Script for testing your implementation.
python3 test.py -h
usage: test.py [-h] [-t TEST] [--release] [--log] [-m MALLOC]
options:
-h, --help show this help message and exit
-t TEST, --test TEST test name to run
--release build in release mode
--log build with logging
-m MALLOC, --malloc MALLOC
allocator name, default to "mymalloc"
The most important option is -t <TEST> which allows you to test your implementationwith a single test.
tests/
Directory with test source files and built executables. Some tests in this directory also
contain explanations of what the test is doing, and potential reasons you may be failing
it. You are allowed (and encouraged!) to write your own additional tests and add them to
this file.
bench.py
Script for benchmarking your implementation. The script uses a simple benchmark from
the glibc library which stresses your implementation.
usage: bench.py [-h] [-m MALLOC] [-i INVOCATIONS]
options:
-h, --help show this help message and exit
-m MALLOC, --malloc MALLOC
allocator name, default to "mymalloc"
-i INVOCATIONS, --invocations INVOCATIONS
number of invocations of the benchmark
The default number of invocations for the benchmark is 10. If you want to perform quick
benchmark runs, then you can change the number of invocations to 3 using -i 3 . It is
recommended to use at least 10 invocations if you are reporting results, however.
bench/
Directory with benchmark source files and built executables.
Testing
You can test your implementation of malloc (assuming you have implemented your
allocator in the “ mymalloc.c ” file) by simply running:
python3 ./test.py
The above command will clean previous outputs, compile your implementation, and then
run all the provided tests against your implementation. It will run all tests contained inthe tests/ folder of your repo. If you want to run a single test (such as align ) then
you can run the test script like so:
python3 ./test.py -t align
If you have another implementation in a different file named “different_malloc.c” (for
example), then you can run tests using this implementation with:
python3 ./test.py -m different_malloc
This may be useful if you want to test a different implementation strategy or want to
benchmark two different implementations (Note: bench.py has this same flag).
warn
Note that while you are allowed to include multiple implementations of the
memory allocator in different files, only the one in mymalloc.c will be used
when running the CI tests.
If you have inserted logging calls using LOG() , then you can compile and run tests with
logging enabled like so:
python3 ./test.py --log
Note that some tests which compare output may fail if logging is enabled!
If you want to run a single test directly (for example align ) then you can run it like so:
./tests/align
If you have logging enabled and want to save the log for a particular test (for example
align ) to a file then you can run the following:
./tests/align &> align.log
Make sure you don’t accidentally add the log file to your git repo as these can get quite
large in size!You will almost certainly require using gdb at some point to debug your implementation
and failing tests. You can run gdb directly on a test (for example align ) like so:
gdb ./tests/align
By default the tests and your library are built with debug symbols enabled so you don’t
have to fiddle with enabling debug symbols to aid your gdb debugging.
Note also that you are allowed to (and recommended to) add extra tests for more
complex cases if you like. You can do this by adding extra files in the tests directory
containing tests, following the same format as the existing tests (make sure to use the
mallocing and freeing wrappers provided in testing.h as well). These extra
tests should be automatically included when running test.py . Writing extra tests is
especially helpful if you find the benchmark script bench.py to be crashing.
Internal testing
In addition to tests which verify the malloc interface itself works, and things like data
consistency (data written to a block stays consistent and does not interrupt metadata),
we provide a few tests which use the helper functions you’ve written to verify the
internal workings of malloc and/or particular parts of it. This should help further pinpoint
errors in your code in some simple cases. Note that these tests require you to have used
the helper functions we provided you and implemented them correctly. These tests
reside in the internal-scripts directory and are also run by test.py , and you can
add more yourself too.
Note that it is possible for you to have designed an optimisation in a way which causes
one of these tests to fail even when nothing is actually wrong due to the test expecting
certain internal behavior. If this occurs, as long as you are confident it is not an
implementation issue, it is not a problem; just mention this in your report.
Address sanitizer
The Makefile we have provided uses the GCC flag -fsanitize=address . This enables
the AddressSanitizer which instruments mmeory accesses to detect memory errors at
runtime, such as access to unallocated memory. You can read more about it here:
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html. You may see output
from “asan” in your test output as a result of this. Hopefully this will help you debug
some of your memory-related bugs in this assignment.
Testing the GCThe test.py script does not include tests for the GC, but you can write your own tests
in mygctest.c if you’d like. You will have to modify the Makefile to compile and run
the GC tests you write yourself.
info
There will be additional test cases we use when marking your code that are not
given to you in the assignment repository for both mygc and mymalloc .
Benchmarking
Benchmarking execution time
If you want to benchmark your code, then you will have to install some python libraries,
namely numpy and scipy . This can be achieved by using pip3 , python’s package
manager:
pip3 install numpy scipy
This will install the two libraries to your local user (as opposed to system-wide). This is
the recommended method for installing per-user packages for python.
Benchmarking your code works in a similar way as testing:
./bench.py
This will run the provided benchmark ( glibc-malloc-bench-simple ) from glibc 10
times and provide you the average. If you are benchmarking, it is highly recommended to
close all other intensive applications on your machine as you may get random
interference otherwise. If you want to report your benchmark numbers, it is important to
note what CPU and memory speed you were using in your report.
Just like the test script, you can switch the malloc implementation using the
-m <MALLOC> flag. This is useful as you may want to have two different
implementations that you want to compare performance on.
If you have time, you might also find interesting results by experimenting with the
sizes/number of mallocs done by the benchmark.Benchmarking fragmentation
For benchmarking fragmentation, we provide the internal test
internal-scripts/fragmentation.c . This tests provides a number of random
allocations and frees. There is then a space in the code containing a TODO where you
are able to calculate fragmentation and report it. You can run this script the same way as
the other tests ( test.py ).
As described earlier, how exactly you calculate fragmentation is up to you, but we
require that you implement at least the peak memory utilisation metric described in
lectures.
If you have time, you might also find interesting results by experimenting with the
compile time constants at the top of the file.
Submitting your work
Submit your work through Gitlab by pushing changes to your fork of the assignment
repository. A marker account should automatically have been added to your fork of the
Assignment 1 repo (if it isn’t there under “Members” then let one of your tutors know).
We recommend maintaining good git hygiene by having descriptive commit messages
and committing and pushing your work regularly. We will not accept late submissions.
Submission checklist
The code with your implementation of malloc in mymalloc.c .
The code with your implementation of the GC in mygc.c
The report.md is in the top-level directory.
(Optional) Any optional tests and benchmrks you want us to look at.
Your statement-of-originality.md has been filled out correctly.
Gitlab CI and Artifacts
For this assignment, we provide a CI pipeline that tests your code using the same tests
available to you in the assignment repository. It is important to check the results of the
CI when you make changes to your work and push them to GitLab. This is especially
important in the case where your tests are passing on your local machine, but not on the
CI - it is possible your code is making incorrect assumptions about the machine your
memory allocator is running on. If you’re failing tests in the CI then it is best to have a
0033.Linux 系统调用 权限低,不能直接操作硬件、内核资源;拥有最高权限,系统调用就是切换这两种状态的入口。系统调用是用户态进程向内核态请求操作系统服务的,是用户程序和 Linux 内核之间的"门"。 阅读详情

相关推荐

C51:PWM+舵机角度控制

PWM,英文名Pulse Width Modulation,是脉冲宽度调制缩写,它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平的时间占据整个信号周期的百分比,例如方波的占空比就是50%.脉冲宽度调制通过占空比编码模拟信号一个周期内,高电平占据时长的百分比如下图所示,最便宜的舵机sg90,常用三根或者四根接线,黄色为PWM信号控制。

qq_73379310的博客 3392

边缘部署提速利器:TensorRT + ONNX 推理优化全解析

本文介绍了在工业智能化转型中,如何通过TensorRT实现YOLO姿态检测模型的边缘端高效部署。首先详细说明了TensorRT环境安装步骤,包括CUDA、OnnxRuntime和TensorRT的版本对应关系,以及通过NVIDIA官网下载安装TensorRT的方法。然后展示了将YOLO模型转换为TensorRT引擎(.engine格式)的代码示例,重点介绍了模型导出时的关键参数设置(如FP16加速、固定尺寸等)以及转换过程中的性能优化。文章通过日志记录展示了模型转换的全过程,包括ONNX中间格式生成和最终T

pengxiang1998的博客 278

手把手教你用SpringBoot+Vue3+Docker从零搭建一个在线OJ系统(附完整源码)

本文详细介绍了如何使用SpringBoot、Vue3和Docker从零搭建一个在线OJ系统,涵盖前后端开发、判题机实现及Docker容器化部署。通过完整的源码和实战步骤,帮助开发者掌握OJ系统的核心架构与关键技术,适用于算法训练、编程竞赛等场景。

weixin_42648844的博客 298

Linux输入输出重定向与用户管理精要

本文系统梳理了Linux输入输出与用户组管理核心内容。输入输出部分涵盖字符设备与块设备区别、文件描述符、重定向与管道机制,重点解析2>&1等易错点;用户管理部分详解3A安全机制、用户分类、配置文件及常用命令(如useradd、passwd、sudo),强调权限最小化与安全审计。全文突出实践应用,适用于系统运维与考试复习。

2301_80092853的博客 644

SMARTFORMS实战:用Template+Loop实现复杂表格布局(附避坑指南)

本文深入解析了SMARTFORMS中Template与Loop组合实现复杂表格布局的实战技巧,突破传统TABLE组件的限制。通过多级表头、单元格合并等案例演示,提供从基础架构搭建到动态数据绑定的完整解决方案,并分享性能优化与异常处理的最佳实践,助力开发者高效应对企业级报表设计挑战。

numpy6sculptor的博客 805

YOLOv5+Astra Pro Plus深度相机:手把手教你实现实时目标检测(附ROS配置技巧)

本文详细介绍了如何将YOLOv5目标检测算法与Astra Pro Plus深度相机结合,构建实时目标检测系统。内容涵盖从硬件选型、环境搭建、ROS配置到YOLOv5部署与深度信息融合的完整流程,并分享了性能优化、避障算法等实战技巧,帮助开发者在机器人视觉等场景中快速实现智能感知应用。

weixin_28292761的博客 392

Linux 网络排障实战:工业边缘场景下的 ss 与 netsta

工业网关的网络问题 — 服务起不来、连接堆积、外联异常 — 大多能从 socket 状态入手定位。;netstat 属于已停止维护的 net-tools,本文仅作对照。从工程实战角度梳理连接排查的完整用法。

ZenovaEdgeOS的博客 457

Vue3 - 强力解决前端下载二进制流pdf文件、下载成功后打开空白问题解决,或者获取PDF文件流,将blob对象转换成下载链接打开后一片空白(无论是否使用pdf插件下载,还是原生方法下载都完美解决)

vue3前端下载二进制流pdf文件,下载成功,打开空白问题解决,js下载PDF文件流,打开空白问题,VUE3 h5中的文件流下载和指定的url下载总结(解决下载后的pdf打开空白情况)pdfjs打开文件流空白,解决pdf文件流,预览全是空白页,pdf文件流,下载正常,但是预览全是空白页,前端JS获取PDF文件流,将blob对象转换成下载链接打开后一篇空白的问题,前端文件流下载后文件空白,前端下载文件流PDF文件显示空白 或 无法打开,在线预览PDF文件打不开白屏怎么办,前端axios请求二进制数据流转换生成

🏆 前端领域优质创作者 4620

USB 技术系列 11 · USB Linux 驱动框架

本文系统解析Linux USB驱动框架,涵盖USB Core、HCD(xhci-hcd/dwc3)、类驱动(CDC/HID/Mass Storage)分层架构,详解usb_device_id匹配、probe/disconnect生命周期及Device Tree配置。结合RISC-V N300实战,揭示Host/Device双模式驱动开发核心逻辑,助力嵌入式BSP开发者掌握USB子系统全栈能力。

peter_pan_study的博客 291

Claude Code 实战 从零教你用 Claude Code 干活

Claude Code 实用指南:AI 编程助手的核心功能与使用技巧 Claude Code 是 Anthropic 推出的智能编程助手,可直接在本地环境中执行操作,相比传统 AI 对话工具具有显著优势:能直接读取项目文件、自动执行修改、记忆项目规则,并支持连接外部服务。本文详解其安装配置、三大核心场景(资料搜索、网页抓取、文章撰写)及进阶功能(Skills、MCP协议、斜杠命令)。特别提供了工作模式切换、CLAUDE.md配置文件等实用技巧,并附常见问题解决方案,帮助用户高效利用这一"坐在身边的

2401_84052244的博客 7637

Vue3 - 详解实现网站接入钉钉扫码登录功能,钉钉授权生成登录二维码用户用手机扫描二维码登陆,支持弹框式、浏览器单独新开页显示,钉钉扫描二维码登录详细流程及示例代码,最新vue集成钉钉扫码授权登录!

vue3,nuxt3,钉钉,扫码登录,vue3钉钉扫码登陆,钉钉授权第三方WEB网站扫码登录功能,钉钉扫码登录第三方网站,单点登录,二维码不显示,报错,扫了没反应,出错,vue3钉钉扫码登录,内嵌,获取个人信息,pc网页钉钉登录,钉钉扫码登录怎么新开一页,跳页显示二维码,内嵌登录二维码,iframe新页面弹出,弹出一个小窗口显示登录二维码,登录报错,扫码没反应,解决手机点登录报错没反应,官方文档,手机扫描钉钉二维码登录网站,页面弹出一个小窗口而不是打开一个页面,vue3中使用iframe实现另开小窗口扫码登

🏆 前端领域优质创作者 3697

Linux的管道符与重定向符

在讲解具体符号前,必须先理解 Linux 进程处理数据的三个默认通道(文件描述符):重定向和管道的本质,就是改变这些数据流的默认指向。将命令原本要打印在屏幕上的结果,写入到文件中。示例:(将 目录的详细列表写入 ,屏幕不再显示)示例:(在 末尾新增一行日志)示例:(若权限不足, 报错会被写入 ,屏幕无显示)示例(推荐用 ):(安装过程中的正常提示和报错信息,统统存入 )示例(传统写法):(注意顺序:先把 stdout 指向文件,再把 stderr 指向 stdout 当前的位置)示例:(命令执行,但屏蔽

Yisitelz的博客 209

AIGC实战——多模态模型DALL.E 2

DALL.E 2 是 OpenAI 提出的一个大规模文本生成图像模型,可以根据文本提示生成各种风格的逼真图像。它通过将预训练模型 CLIP 与 GLIDE 中的扩散模型架构相结合完成任务。它还具有其他应用,例如通过文本提示编辑图像和提供给定图像的变体。虽然它也有一些局限性,例如不一致的文本渲染和属性绑定,但 DALL.E 2 是仍然一个非常强大的AI模型,推动了生成模型的发展。

盼小辉丶的博客 1万+

Linux 学习 - 第十五周作业

与 2.4 步骤相同, 唯一差别是先装 docker, 再用 cri-dockerd 把 docker 适配成 CRI, 因为 v1.24 之后移除了内置的 dockershim。组件之间只有一条通道: 全部组件都 watch 或写入 kube-apiserver, 由 apiserver 落 etcd, 组件之间从不直接通信。设置 immutable: true 后不能修改, 只能删除重建。全程异步、watch 驱动, 没有任何组件去命令另一个组件, 这就是声明式架构的本质。

corey93的博客 192

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

linux用phytool测试mdio接口的phy芯片

【代码】linux用phytool测试mdio接口的phy芯片。

qq_26074053的博客 209

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Instabox 云端 Linux 虚拟机配置中文拼音输入法

Fcitx5 和拼音已安装、桌面会话加载了输入法环境变量、Fcitx 当前处于激活状态。在这次 Debian + XFCE 排查中,拼音本来已经安装;问题出在桌面会话没有正确加载变量,而且 Fcitx 需要再次激活。配置登录环境并执行后,当前输入法显示为pinyin,中文输入恢复正常。

binweisili的博客 140

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【Linux】35:应用层自定义协议和序列化

本文实现了一个基于TCP字节流的网络计算器,通过自定义协议(长度头+JSON)解决粘包问题。核心在于应用层协议设计:使用Jsoncpp进行序列化与反序列化,以“长度\r\nJSON报文\r\n”格式封装数据,确保读取完整性。服务端采用多进程模型(二次fork)处理并发请求,客户端循环输入并发送请求,服务端计算后返回结果。项目融合了Socket编程、多进程、策略模式日志、RAII锁等技术,完整演示了从底层通信到高层业务的全栈实现。

qq_62473190的博客 111

Linux 常用命令 + GCC 编译全流程详解

本文为Linux与C语言初学者打造的实战指南,涵盖命令行核心技能:从文件操作、权限管理到查找、进程控制、打包压缩,最终深入剖析GCC编译四阶段(预处理、编译、汇编、链接),揭示gcc hello.c -o hello背后的完整流程。通过建立“一切皆文件”“命令即程序”等心智模型,帮助读者在纯命令行下完成代码开发全闭环,真正理解底层机制,适用于面试准备、跨平台开发及服务器部署场景。

2401_88413914的博客 307

嵌入式 Linux OOM Killer 触发逻辑与防误杀实战指南

本文深入解析嵌入式 Linux 下 OOM Killer 的触发机制,结合工业网关真实工程场景,提供从日志排查、内核参数调优到关键进程保护的完整落地方案,解决核心进程被误杀导致的业务中断问题。

嵌入式扫地僧 430

Windows 下 QEMU 搭建 ARM64 Linux 开发环境完整教程 | 保姆级步骤 + SSH 远程登录

本文针对嵌入式开发、跨架构软件测试、ARM Linux 学习的开发者,提供一套在 Windows x86 电脑上零成本搭建 ARM64 虚拟机的完整方案。全程使用开源工具,覆盖环境安装、系统部署、远程登录、性能优化全流程,新手可直接照着步骤操作。

wutu_csdn_blog的博客 332

Linux epoll 一篇讲透:从 select/poll 到红黑树、LT/ET,再到完整 TCP 服务器

一万个客户端已经连上服务器,眼下只有十个客户端发来了数据。服务器怎样把时间花在这十个连接上?理解这个问题,就抓住了 epoll 的主线。接下来,我们沿着“为什么需要它 → 接口怎么用 → 内核如何实现 → LT/ET 怎么写 → 完整服务器怎么运行”的顺序,把知识连起来。**阅读基础:**了解socketbindlistenaccept的基本用途即可。本文示例面向 Linux,服务器使用 C++17,实验脚本使用 Python 3。

2601_94861874的博客 491

Linux FFmpeg深度解析之av_probe_input_format调用流程与实战(四十八)

本篇目的:理解如何根据选择输入格式,并通过构造WAV探测数据观察demuxer评分与格式返回结果。FFmpeg需要先确定输入数据属于哪种封装格式,才能选择对应的demuxer读取文件头和媒体包。接收调用者准备好的探测数据,遍历可用输入格式并返回匹配的。它只负责根据现有探测数据猜测格式,不负责从文件或网络读取数据,也不负责打开输入和解析媒体流。fill:#333;important;important;fill:none;color:#333;color:#333;important;

Android系统攻城狮 379

02 Linux 基础环境:Shell 命令行操作

正则表达式(Regular Expression,简称 Regex)是一种用于描述字符串匹配规则的表达式。它可以用于:搜索指定格式的文本。提取日志中的关键信息。验证字符串格式。批量替换文本。分析程序运行日志。在 Linux 中,grepsed和awk都支持不同形式的正则表达式。进程(Process)是程序运行时的实例。程序是存储在磁盘中的可执行文件,而进程是程序运行后由操作系统创建并管理的执行实体。每个进程通常具有:PID:进程 ID。PPID:父进程 ID。UID:进程所属用户。

2301_76633800的博客 277

深入浅出聊聊 Linux 的 PageCache 与系统极致性能

本文深入浅出解析了 Linux PageCache 的核心机制,揭示其如何通过“延迟写、预读读”提升系统性能。以监控告警为切入点,阐明 free -h 中 buff/cache 并非真正占用,真正可用内存由 available 决定。结合 Kafka、Elasticsearch、MySQL 等实战场景,说明中间件如何依赖 PageCache 实现极致性能。强调不可手动清理缓存,并建议合理调优脏页参数,避免卡顿。最终指出:内存满≠危机,而是系统高效运行的体现。

小小默:进无止境 529

【Linux 系统篇(四十)】线程(一):从进程到线程,再到虚拟内存与分页机制

在正式学习 Linux 线程之前,我们需要先思考一个问题:为什么已经有了进程,还需要线程?在之前的学习中,我们已经接触过进程,知道进程是操作系统进行资源分配的基本实体,操作系统通过等内核数据结构管理进程。我们也知道,一个进程拥有自己的代码、数据、堆、栈以及虚拟地址空间。那么问题来了:接收用户输入;处理用户提交的数据;将处理结果写入文件。如果只有一个执行流,那么程序就需要按照一定的顺序执行这些任务。当其中某项任务需要等待时,其他任务也可能无法及时得到执行。

Huang_jin007的博客 542

【Linux 命令实战(06):Linux 文件权限管理,掌握 chmod、chown、chgrp】

chmod:修改文件和目录权限。chown:修改文件所有者,也可以修改所属用户组。chgrp:修改文件所属用户组。r:读取。w:写入。x:执行,对于目录则表示进入和访问能力。ugo:分别代表所有者、所属组和其他用户。我认为,权限管理最重要的不是记住755644这些数字,而是先弄清楚谁需要访问文件、需要执行什么操作,再给出恰当的权限。尤其是在测试服务器和生产服务器上,不要为了图方便直接使用chmod 777。权限开放得越大,并不代表问题解决得越好。

一些微不足道的见解、希望能帮助各位 352
上一篇: SWD604 Program Design and Construction
下一篇: Interactive Employee Management System
wx__codinghelp
博客等级 码龄2年 514粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值