#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/fileio.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/vim.h"
Macros | |
#define | MEMFILE_PAGE_SIZE 4096 |
#define | MHT_LOG_LOAD_FACTOR 6 |
#define | MHT_GROWTH_FACTOR 2 |
Functions | |
memfile_T * | mf_open (char_u *fname, int flags) |
int | mf_open_file (memfile_T *mfp, char_u *fname) |
void | mf_close (memfile_T *mfp, bool del_file) |
void | mf_close_file (buf_T *buf, bool getlines) |
void | mf_new_page_size (memfile_T *mfp, unsigned new_size) |
bhdr_T * | mf_new (memfile_T *mfp, bool negative, unsigned page_count) |
bhdr_T * | mf_get (memfile_T *mfp, blocknr_T nr, unsigned page_count) |
void | mf_put (memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile) |
void | mf_free (memfile_T *mfp, bhdr_T *hp) |
Signal block as no longer used (may put it in the free list). More... | |
int | mf_sync (memfile_T *mfp, int flags) |
void | mf_set_dirty (memfile_T *mfp) |
bool | mf_release_all (void) |
blocknr_T | mf_trans_del (memfile_T *mfp, blocknr_T old_nr) |
void | mf_free_fnames (memfile_T *mfp) |
Frees mf_fname and mf_ffname. More... | |
void | mf_set_fnames (memfile_T *mfp, char_u *fname) |
void | mf_fullname (memfile_T *mfp) |
bool | mf_need_trans (memfile_T *mfp) |
Return true if there are any translations pending for memfile. More... | |
#define MEMFILE_PAGE_SIZE 4096 |
An abstraction to handle blocks of memory which can be stored in a file. This is the implementation of a sort of virtual memory.
A memfile consists of a sequence of blocks:
The size of a block is a multiple of a page size, normally the page size of the device the file is on. Most blocks are 1 page long. A block of multiple pages is used for a line that does not fit in a single page.
Each block can be in memory and/or in a file. The block stays in memory as long as it is locked. If it is no longer locked it can be swapped out to the file. It is only written to the file if it has been changed.
Under normal operation the file is created when opening the memory file and deleted when closing the memory file. Only with recovery an existing memory file is opened.
The functions for using a memfile:
mf_open() open a new or existing memfile mf_open_file() open a swap file for an existing memfile mf_close() close (and delete) a memfile mf_new() create a new block in a memfile and lock it mf_get() get an existing block and lock it mf_put() unlock a block, may be marked for writing mf_free() remove a block mf_sync() sync changed parts of memfile to disk mf_release_all() release as much memory as possible mf_trans_del() may translate negative to positive block number mf_fullname() make file name full path (use before first :cd)
#define MHT_GROWTH_FACTOR 2 |
#define MHT_LOG_LOAD_FACTOR 6 |
The number of buckets in the hashtable is increased by a factor of MHT_GROWTH_FACTOR when the average number of items per bucket exceeds 2 ^ MHT_LOG_LOAD_FACTOR.
Close a memory file and optionally delete the associated file.
del_file | Whether to delete associated file. |
Close the swap file for a memfile. Used when 'swapfile' is reset.
getlines | Whether to get all lines into memory. |
Signal block as no longer used (may put it in the free list).
Make name of memfile's swapfile a full path.
Used before doing a :cd
Return true if there are any translations pending for memfile.
Get a new block
negative | Whether a negative block number is desired (data block). |
page_count | Desired number of pages. |
Set new size for a memfile. Used when block 0 of a swapfile has been read and the size it indicates differs from what was guessed.
Open a new or existing memory block file.
fname | Name of file to use.
|
flags | Flags for open() call. |
Open a file for an existing memfile.
Used when updatecount set from 0 to some value.
fname | Name of file to use.
|
Release the block *hp.
dirty | Whether block must be written to file later. |
infile | Whether block should be in file (needed for recovery). |
Release as many blocks as possible.
Used in case of out of memory
Set dirty flag for all blocks in memory file with a positive block number. These are blocks that need to be written to a newly created swapfile.
Set the simple file name and the full file name of memfile's swapfile, out of simple file name and some other considerations.
Only called when creating or renaming the swapfile. Either way it's a new name so we must work out the full path name.
int mf_sync | ( | memfile_T * | mfp, |
int | flags | ||
) |
Sync memory file to disk.
flags | MFS_ALL If not given, blocks with negative numbers are not synced, even when they are dirty. MFS_STOP Stop syncing when a character becomes available, but sync at least one block. MFS_FLUSH Make sure buffers are flushed to disk, so they will survive a system crash. MFS_ZERO Only write block 0. |